Solved

How to change focus from one form to another

Posted on 1998-07-06
4
160 Views
Last Modified: 2010-04-04
I expected this to be easy but have been struggling with it.  My application has two forms - one AppBar docked to the bottom of the screen and another one maximized, so the two are visible at all time. The AppBar for has to be created first and then the other form is created. As a result the AppBar has the focus initially.  How can I make the other form (which has one Tedit on it) have the focus.  I have tried a few obvious things like Form1.Setfocus when OnShow, etc...
0
Comment
Question by:ymailhot
4 Comments
 
LVL 1

Expert Comment

by:michaue
ID: 1357209
Make Form1.ActiveControl = to the TEdit in the OnShow event of Form2 put the following

Form1.Show;

Hope it works

Elfrieda :)
0
 

Expert Comment

by:LilitaN
ID: 1357210
Try in AppBar.OnShow event set Screen.ActiveForm := form1

Lilita
0
 

Author Comment

by:ymailhot
ID: 1357211
Comment from LilitaN:  The Screen attribute is read only so the only way to bring the focus to a form is to use setfocus. This was the first thing I tried (AppBar OnShow Event with Form2.SetFocus). For some reason the focus remains on the appbar.

Solution from Michaud: I tried that too. I get the message cannot focus on an invisible object or something like that.  I just went to try it again and now I don't even see the objects from Form2 in ActiveControl of AppBar.

Thank you.
0
 
LVL 3

Accepted Solution

by:
vladika earned 50 total points
ID: 1357212
I found two ways to solve your problem

1) If AppBar is MainForm, just set AppBar.Visible and Form1.Visible to TRUE.
After that AppBar created first and at once become visible,
then Form1 created and become visible too and FOCUSED.

2) set AppBar.Visible = False and write AppBar OnFormActivate handler
procedure TAppBar.FormActivate(Sender: TObject);
const First: Boolean = True;
begin
  if First then
  begin
    Form1.Show; // if first call then show Form1
    Windows.SetFocus(Form1.Handle); // ... and set focus
    First := False;
  end;
end;


0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to fill array with TArray.Create? 14 90
Delphi TcxGrid group footer summary 3 276
Delphi XE10 Round Image 2 129
Not able to call Delphi XE10 dll function from Delphi 6.0 4 28
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

822 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question