Solved

How to change focus from one form to another

Posted on 1998-07-06
4
157 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now