How to create a top level control?

  • Thread starter Thread starter Mike Scott
  • Start date Start date
M

Mike Scott

I'd like to create a control that's top-level, i.e. parented by the
Windows desktop - something like a tooltip or menu.

When I call SetTopLevel( true ) in my control, Windows Forms (or is it
Windows?) creates a form and hosts my control in it!

There must be an easy way to create a true top-level control in Windows
Forms that isn't hosted/parented by a Windows Forms form.

Help!?

Cheers,

MikeS.
 
Mike Scott said:
I'd like to create a control that's top-level, i.e. parented by the
Windows desktop - something like a tooltip or menu.

When I call SetTopLevel( true ) in my control, Windows Forms (or is it
Windows?) creates a form and hosts my control in it!

There must be an easy way to create a true top-level control in Windows
Forms that isn't hosted/parented by a Windows Forms form.

Why must there?

By definition a control must be in a form. Tooltips are not controls they
are components (this is confused by the documentation that referes to them
as controls in various places) that manipulate a top level window/form to
which you have no direct access.

I suspect that what you want is simply to create a form and turn off the
borders and title (f.FormBorderStyle = FormBorderStyle.None)
 
Hi Nick

I say "there must be an easy way" because, firstly, a form is a control,
as a component is a control. To Windows, they're all just window
handles. I've been programming Windows for 20+ years, since the Petzold
days. So I expect there must be a way to create a control that doesn't
have to be hosted in a form. Like I said, a *form* is a control that's
not hosted in a form, so there is a way.

If it's not easy, it must be because WinForms is going out of its way to
make it not easy, since there's no intrinsic reason why it should be hard.

Cheers,

MikeS.
 
Hi Mike,

A Component is NOT a Control.
Tooltip is a Component and therefore is not a control and has no handle.

Obviously the visual bit that it controls does have a handle but you can't
get at it and I see no reason to believe (other than simplicity) that it
isn't a form with the border turned off.

What about my suggestion of using a form with the border turned off?

Or NativeWindow if you must.
 
Hi Nick

Sorry, you're right about component. However, a form is a control and it
can be top-level.

As for using a form with no border - tried that! That's what my other
thread is about "Zero-sized form" that you've been participating in :-)

Ideally I just need a control, not a form though that obviously works.
This is partly a learning exercise - I can do it easily in native
Windows and I'm trying to figure out how to do it in WinForms.

Thanks for your help.

MikeS.
 
Back
Top