Solved

How to change focus from one form to another

Posted on 1998-07-06
4
163 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

733 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