Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Set focus to a child window

Posted on 2004-08-17
6
Medium Priority
?
357 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 750 total points
ID: 11878244
any results?
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

618 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