Sign in to follow this  
InsaneBoarder234

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

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
DaWanderer    538
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
Rob Loach    1504
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this