Creating a Hidden Modeless Form

  • Thread starter Thread starter Joel Matthias
  • Start date Start date
J

Joel Matthias

Hi,

I know this topic has been covered in various forms but I still can't
seem to come up with a solution that works correctly.

I want to create a modeless hidden form in my application. This is NOT
the main application form. The best way so far is as follows.

MyForm form = new MyForm();
form.Show();
form.Visible = false;

This works but the form is visible for a brief period. Even when I make
the form size 0,0 it's still visible for a brief time.

So is it possible to create a hidden .NET form that is never displayed
to the user?

Thanks - Joel
 
Joel Matthias said:
Hi,

I know this topic has been covered in various forms but I still can't
seem to come up with a solution that works correctly.

I want to create a modeless hidden form in my application. This is NOT
the main application form. The best way so far is as follows.

MyForm form = new MyForm();
form.Show();
form.Visible = false;

This works but the form is visible for a brief period. Even when I make
the form size 0,0 it's still visible for a brief time.

So is it possible to create a hidden .NET form that is never displayed
to the user?

Thanks - Joel

Just don't call the Show() method.
 
Hi,

I did try this and if Show() is not called the form is not created. I
have double checked this by using Spy++ and my overriding WndProc() and
placing a breakpoint there. Show() or ShowDialog() is required to
create the window.

Thanks

Joel
 
Joel said:
Hi,

I did try this and if Show() is not called the form is not created. I
have double checked this by using Spy++ and my overriding WndProc() and
placing a breakpoint there. Show() or ShowDialog() is required to
create the window.

By any chance are you trying to make this your startup form and start a
message loop on it with Application.Run?

In that case, you are right.

I assumed that the "hidden" form was an additional form in your project. In
that scenario, the second form is loaded and all properties and methods are
available and functioning.
 
Hi,

It is NOT the main startup form. If you do not call Show() or
ShowDialog() the underlying window is not created and hence there is no
message loop for it. I need the message loop to function so I can
intercept a broadcast message.

Joel
 
You could create a form or even a NativeWindow based class and show it but
position it offscreen. This is a well known technique.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
Why create a Form so you can intercept a broadcast message? Why not
just write a class that creates a thread and a socket to receive it? No
form is needed then.
 
Hi Joel,

Have you tried form.CreateHandle() without form.Show()?
After form.CreateHandle() my breakpoints in WndProc() were reached
without the form being visible.
 
Back
Top