Child Form Focus Problem

I

Ian

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
 
S

Stoitcho Goutsev \(100\) [C# MVP]

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
 
I

Ian

That's exactly what I was looking for -- thanks!

Ian

Stoitcho Goutsev \(100\) said:
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

--
HTH
Stoitcho Goutsev (100) [C# MVP]


Ian said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top