Solved

Set focus to a child window

Posted on 2004-08-17
6
337 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

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

Title # Comments Views Activity
Run video youtube webbrowse 10 86
select query - oracle 16 103
When i run adoquery my application freezes 26 209
Slow Restore if incremental backups using RDiff.exe 4 51
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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

734 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