Update secondary form without changing primary focus

Asked

Viewed 2,309 times

4

I developed a program in Delhi that has two Forms, one with a grid and another with a map, the operation is simple: when clicking on the grid the position of the vehicle is updated on the map, the problem is that every time I call the Procedure in the map form to update the position I miss the focus of the form containing the grid, and even if I throw the focus back it gets ugly the windows changing colors due to loss of focus.

How can I update the secondary window data without passing the focus to it?

  • 1

    The fact that you call a form method does not imply passing the focus on to it, so I imagine you are triggering some operation that shifts focus. How you command the secondary window update?

  • There is not enough information to solve your problem. Please post the code of a simple program with the problem.

  • Thanks to the tips of all of you I’ve discovered that one of the components I’m using asks for the focus when called, using Raphael Zimermann’s tip I’m setting the visibility to false, calling the composition and setting it to true. Which in this case is no problem because the function draws on the screen and what it does is delete from one point and create in another.

3 answers

2


Try this:

procedure BotãoFormGridClick(Sender: TObject);
begin

   FormulárioMapa.Visible := False; // Oculta o form, fazendo com que qualquer 
                                   // foco não seja executado
   FormulárioMapa.ProcedimentoMapa(); // Executa seu procediemnto
   FormulárioMapa.Visible := True; // Não usar um 'Show()'. Com o visible, 
                                   // ele volta a aparecer sem executar um foco

end;

1

In accordance with an answer in stackoverflow.com, you can make a window not have the focus enabled on it by overwriting the Createparams function and in C# it looks like this:

private const int WS_EX_NOACTIVATE = 0x08000000;
protected override CreateParams CreateParams
{
    get
    {
        CreateParams createParams = base.CreateParams;
        createParams.ExStyle = WS_EX_NOACTIVATE;
        return createParams;
    }
}

Already in this article from Delphi.about.com, we have that this function can be about writing in Delphi as follows:
first

private
procedure CreateParams
 (var Params: TCreateParams); override;

2nd

procedure TForm.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);

{ -- seu código aqui -- }

end;

Great are the chances that if you can reproduce the function shown in C# in Delphi you will get the same result by changing.

-1

  • Avoid making the entire answer depend on an external link. Usually the answers contain an explanatory text, an example code snippet (something that solves the main question of the question) and a reference link (a more extensive content where you could find more details about the solution). So if one day the link gets off the air, the content of the OS remains for consultation.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.