Jump to content
  • Advertisement
Sign in to follow this  
InsaneBoarder234

[.net] VB.NET - Hide form on startup

This topic is 4417 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been searching for this for a while now but to no avail. I'm making the move from VB6 to VB.NET 2003 and in the project I'm currently working on I have a single form that I need to have hidden on startup and then display at certain times. I've tried various things that I have managed to find. Firstly I tried the obvious Me.Hide() and Me.Visible. Then I tried moving my startup code into a Sub Main as follows:
Public Shared Sub Main()
    ''''''''''''''''''''
    ' Setup the form
    ''''''''''''''''''''
    Dim frm As New frmMain
'    frm.Hide()/frm.Visible = False
    Application.Run(frm)
End Sub

Note that the commented like is meant to show that I have tried both frm.Hide() and frm.Visible = False, but again it didn't work. Any ideas anyone? Thanks!

Share this post


Link to post
Share on other sites
Advertisement
It's a little morein evolved than that for some technical reasons.

See here.

However, my advice would simply be to delay the form creation at all until you first need it.

Share this post


Link to post
Share on other sites
I would recommend handling the "Load" event of the form and calling Hide() there. You can also manually run the application's loop instead of using Application.Run (which calls Form.Show) as such:


Public Shared Sub Main()
Dim frm As New frmMain

While frm.Created
Application.DoEvents()
End While
End Sub



The form will not be shown until you call frm.Show() on it. Hope this helps!

Share this post


Link to post
Share on other sites
Quote:
Original post by DaWanderer
I would recommend handling the "Load" event of the form and calling Hide() there.

Sorry, I forgot to mention that I tried "Me.Hide()" and "Me.Visible = False" within both the Form_Load and the Form_Activate events, and it doesn't work.

Either way, thanks for the help both of you, I'm going to take Microsoft's and jfclavette's advice and run my application in a Main() sub and only load my form when I need to use it.

Thanks!

Share this post


Link to post
Share on other sites
In the "Shown" event, call this.Hide() .

If you don't want the form to show when the user presses ALT-Tab, you're going to have to override CreateParams:


#region CreateParams
// Thank you goes to uavfun for this awesome finding to disable the alt tab form.
private static uint WS_POPUP = 0x80000000;
private static uint WS_EX_TOPMOST = 0x00000008;
private static uint WS_EX_TOOLWINDOW = 0x00000080;
private static uint WS_MINIMIZE = 0x20000000;

protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.Style = unchecked((int)(WS_POPUP | WS_MINIMIZE));
cp.ExStyle = (int)WS_EX_TOPMOST + (int)WS_EX_TOOLWINDOW;

// Set location
cp.X = 100;
cp.Y = 100;

return cp;
}
}
#endregion CreateParams



This is a snippet of code from ScreenCap.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!