|
-
Oct 26th, 2006, 06:45 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] Form hide on startup
hi guys! I put this code under Form_load to make my form hide when it is loaded but it didn't work. Is there something I missed or it is not the right way to implement it?
-
Oct 26th, 2006, 07:09 PM
#2
Re: Form hide on startup
The issue is that the form is Visible by default. So when you load a form it has to show before it can do anything else. Upon completion of the load event you can use another event and call your hide code.
Perhaps placing your code in the Form1_Activated or Form1_VisibleChanged events.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Oct 26th, 2006, 07:13 PM
#3
Frenzied Member
Re: Form hide on startup
hide isn't the thing to use. try this.Visible = false;
-
Oct 26th, 2006, 07:45 PM
#4
Re: Form hide on startup
It is not possible to hide a form, either by calling Hide or by setting Visible to false, in the form's Load event handler. That's because once the Load event is raised, the form is going to be visible when it completes no matter what. When I say "visible" I mean that it's Visible property will be true. In C# 2005 you would use this code:
Code:
private void Form1_Load(object sender, EventArgs e)
{
// Minimise the form so that the user can't see it.
this.WindowState = FormWindowState.Minimized;
// Don't show the form in the task bar.
this.ShowInTaskbar = false;
}
// The Shown event is raised immediately after the Load event completes and the form becomes visible.
private void Form1_Shown(object sender, EventArgs e)
{
// Now it is possible to hide the form for real.
this.Visible = false;
// Set the WindowSate back to Normal here if desired.
}
Note that the WindowState and ShowInTaskbar properties can be set in the designer rather than using the Load event handler. In previous versions of C# you would have to use the Activated event rather than Shown, which is new in .NET 2.0. In that case you would require a class-level boolean variable to remember whether this was the first time the form was activated.
-
Oct 26th, 2006, 08:25 PM
#5
Thread Starter
Fanatic Member
Re: Form hide on startup
Sorry guys i think i have not explain it well. anyway, I set from registry to run my application automatically when windows start, what im trying to do is to hide the form when it is loaded when windows start but it still can be shown when the users double click the icon from the system tray. In other words, what im trying to do is like MSN messenger which load it self into system tray with out showing the main form.
-
Oct 26th, 2006, 09:09 PM
#6
Re: Form hide on startup
 Originally Posted by daimous
Sorry guys i think i have not explain it well. anyway, I set from registry to run my application automatically when windows start, what im trying to do is to hide the form when it is loaded when windows start but it still can be shown when the users double click the icon from the system tray. In other words, what im trying to do is like MSN messenger which load it self into system tray with out showing the main form.
No problem. You simply use the code I provided. I have done exactly the same thing in a previous app of my own. My app had the option to run at startup and if that was selected then there was an option to run minimised. If the user selected the option to run at startup I would add a value to the Run key in the registry. If the user also selected the minimised option then I'd add a "-min" argument to the commandline stored in the registry. In my app I used Environment.GetCommandLineArgs to check whether the commandline included the "-min" switch. If it did then I executed code much like I posted previously. My app was in VB.NET 2003, so I didn't have the Shown event and had to use the Activated event instead. With Shown it's easier.
-
Oct 26th, 2006, 09:58 PM
#7
Thread Starter
Fanatic Member
Re: Form hide on startup
oh I see..but, does "-min" argument hide my form or just minized it to taskbar?
-
Oct 26th, 2006, 10:03 PM
#8
Re: Form hide on startup
"-min" doesn't do anything. It's just a string. You can pass any commandline argument you like to any executable you like. It's how the code inside handles those arguments that gives them significance. If an application has no code to handle commandline arguments then they will simply be ignored, no matter their number or value. If you want the "-min" swicth to be significant then it's up to you to write the code to make it so. You use the GetCommandLineArgs method get the commandline arguments for the application. If you find "-min" then you execute the code that performs the function that you want to perform. If you just want to minimise the app then just minimise it. If you want to display it only in the system tray then only display it in the system tray. You know how to do both.
-
Nov 8th, 2006, 06:32 PM
#9
Thread Starter
Fanatic Member
-
Nov 17th, 2006, 01:02 AM
#10
Thread Starter
Fanatic Member
Re: Form hide on startup
Thanks for the inputs guys. Now it is working the way i want it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|