?
Solved

How to change focus from one form to another

Posted on 1998-07-06
4
Medium Priority
?
167 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 200 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses
Course of the Month7 days, 21 hours left to enroll

765 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