Solved

Set focus to a child window

Posted on 2004-08-17
6
342 Views
Last Modified: 2010-04-05
i make that a parent of a form2 is a PageControl component under another form1.
when showing the form1 the focus is on it ,and i want to give the focus to form2.
notice : i defined form2.parent as  PageControl who belong to form1.
how can i gave the focus to form2 ???
0
Comment
Question by:mars_r
[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
6 Comments
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 11821043
SetFocusedControl(Form2) perhaps?
0
 
LVL 2

Expert Comment

by:Molando
ID: 11821796
You may have a few small problems with a form in a pagecontrol.
by adding

form2.show;
form2.Enabled := true;
form2.setfocus;

buttons will work, and tabs will work fine, but you will not be able to click on an edit control.
you could try adding a Tapplicationevent to the form then doing something like in the onmessage

 if msg.message=wm_lbuttondown then
  begin
     GetCursorPos( pt );
     pt := form2.screentoclient(pt);

    wc := controlatpos(pt,false,false);
0
 
LVL 2

Expert Comment

by:Molando
ID: 11822241
ok, had a sec to spare. here is the code.
when you set the forms parent do a :

form2.parent := tabsheet1;
form2.top := 0;
form2.left := 0;
form2.enabled := true;
form2.show;
form2.setfocus;

place a tApplicationevent on form 2.
on the onmessage event do this:

var
   wc : tcontrol;
   pt : tpoint;
begin
if msg.message=wm_lbuttondown then //only look at the mouse going down
  begin
     GetCursorPos( pt ); //where is the mouse?
     pt := form2.screentoclient(pt); //where is it relative to our form
    wc := controlatpos(pt,false,true); //get the control related to our form from the mouse pos
    if wc is twincontrol then (wc as twincontrol).setfocus; //make sure it is a win control, if it is then setfocus.
    end;
end;

tested and works.

Molando
0
Technology Partners: 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!

 
LVL 27

Expert Comment

by:kretzschmar
ID: 11822979
usual u should use as borderstyle for your form2 bsNone,
as the parent is a TTabSheet (i guess) of a TPageControl

otherwise use

    PostMessage(form2.Handle, WM_NCACTIVATE, 1, 0);

hope this helps

meikl ;-)
0
 
LVL 3

Expert Comment

by:gandalf_the_white
ID: 11849797
is there reason why you want to insert a form into the pagecontrol?

why don't you insert the content of form2 into a panel and
set the parent of that panel to the pagecontrol?
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 250 total points
ID: 11878244
any results?
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
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.…

695 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