Solved

Set focus to a child window

Posted on 2004-08-17
6
321 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
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

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…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

758 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

22 Experts available now in Live!

Get 1:1 Help Now