Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / July 2004

Tip: Looking for answers? Try searching our database.

Child Form Focus Problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ian - 30 Jul 2004 21:33 GMT
I'm trying to create a form that is only displayed/movable within the
bounds of a parent form (i.e. the child form is clipped to the parent
form's client rectangle).  I don't want to use MDI for this because
the parent form will be an MDI child.  For example, there are three
forms: A, B, and C.  A is an MDI parent form that contains B.  Form C
is a child of B that must stay within the client area of form B.  In
this example, I'm trying to create form C.

I've looked at older posts on this newsgroup that suggests using the
following code in the parent form:

     Form f = new Form();
     f.TopLevel = false;
     f.Parent = this;
     f.Show();

This achieves the clipping effect that I want; however, the child form
does not focus properly.  The title bar of the child form always
remains grayed-out even if I'm moving it around or one of its child
controls is focused.  In addition, the child form never raises the
Activated event and only raises the GotFocus event when minimizing the
child form then maximizing it.

Does anyone know how to get the child form to properly focus (or if
this is even possible)?

Thanks,
Ian
Stoitcho Goutsev \(100\) [C# MVP] - 30 Jul 2004 23:55 GMT
Hi Ian,

There is 3 types of windows in Windows: overlapped windwos, popup windows
and child windows. Well there is 4th type MDI child but it is actually a
child window, but kind of special. Only child windows are clipped inside the
parent. However they never get activated.

But there is a workaround. Unfortunately you it involves PInvoke.

So the thing is when the child form is clicked and it goes above all others
it reveives WM_CHILDACTIVATE message. As a response of this message you need
to send one WM_NCACTIVATE with wParam = 0 to the last active form and send
one WM_NCACTIVATE with wParam = 1 to itself. this will paint the captions
for you

Signature

HTH
Stoitcho Goutsev (100) [C# MVP]

> I'm trying to create a form that is only displayed/movable within the
> bounds of a parent form (i.e. the child form is clipped to the parent
[quoted text clipped - 24 lines]
> Thanks,
> Ian
Ian - 31 Jul 2004 03:27 GMT
That's exactly what I was looking for -- thanks!

Ian

> Hi Ian,
>
[quoted text clipped - 39 lines]
> > Thanks,
> > Ian

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.