472,958 Members | 2,305 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

How to hide form on startup

Hi all,

I am using the Notify Icon sample that came with .Net Docs and was able
to run it. However, I want to start the form as minimized. I have the
ShowInTaskbar = false and in the this is my code in the form load:

private void Form1_Load(object sender, System.EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
this.Visible = false;
}

This will still display a minimized window title bar near the Windows Start
button.
It does not totally hide the form.

Also, can I remove just the "X" or close button of the form and retain the
minimize/maximize buttons?

TIA.
Nov 15 '05 #1
2 51458
Hi Ignacio,

Thanks for the feedback. The form still shows as a minimized titlebar
just above the Microsoft START button. I changed the code as follows:

1. Added to namespace definitions

using System.Runtime.InteropServices;

2. Declared P/Invoke in my Form1 class

[DllImport("user32.dll")]
public static extern int SetWindowLong( IntPtr window, int index, int
value);

[DllImport("user32.dll")]
public static extern int GetWindowLong( IntPtr window, int index);

const int GWL_EXSTYLE = -20;
const int WS_EX_TOOLWINDOW = 0x00000080;
const int WS_EX_APPWINDOW = 0x00040000;

3. I copied this code in the Form1_Load method

this.WindowState = System.Windows.Forms.FormWindowState.Minimized;
this.Visible = false;
this.ShowInTaskbar = false;
int windowStyle = GetWindowLong(Handle, GWL_EXSTYLE);
SetWindowLong(Handle, GWL_EXSTYLE, windowStyle | WS_EX_TOOLWINDOW);
I noticed that the Min/Max buttons are gone as well.
Nov 15 '05 #2
Hi Nicholas,

Thank you for the feedback.

I think this proves that I am indeed a newbie. If I change the WindowState
= Minimized
in the form properties during design time, it actually hides the form when I
run the
code. No other code was necessary.


"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote
in message news:e$**************@TK2MSFTNGP11.phx.gbl...
amil,

I don't think that you can remove the "X" button, but I do think that
you can disable it. Check out knowledge base article Q184686, titled
"HOWTO: Disable the Close Option on Control Menu of a VB Form", located at
(watch for line wrap):

http://support.microsoft.com/default...b;en-us;184686

While this applies for VB6, it will show you which API calls you have to make in order to disable the box.

As for hiding the form, you should probably override the CreateParams
property so that it returns a CreateParams instance that has the appropriate window styles set so that your form is initially minimized.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com
"amil [c#newbie]" <am****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi all,

I am using the Notify Icon sample that came with .Net Docs and was able
to run it. However, I want to start the form as minimized. I have the
ShowInTaskbar = false and in the this is my code in the form load:

private void Form1_Load(object sender, System.EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
this.Visible = false;
}

This will still display a minimized window title bar near the Windows

Start
button.
It does not totally hide the form.

Also, can I remove just the "X" or close button of the form and retain the minimize/maximize buttons?

TIA.


Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: genetic.error | last post by:
I'm moving from Vb6 to VB.Net. I have a feeling this has come up before... The VS.Net MSDN file seems to state that the following should work: Form1.Show Form1.Visible = True Form1.Hide...
9
by: Mark | last post by:
Hi All, I am trying to use the function found on the MVP site http://www.mvps.org/access/api/api0019.htm to hide the Access window. I must be missing something as I keep getting an error message:...
5
by: Kirk Graves | last post by:
Can anyone tell me why this code does not work? Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.Hide() End Sub If runs, but the...
4
by: Matthew | last post by:
The following code does not hide the form. Any ideas why? Also, is there a workaround? I have VB.NET 2003. I have a system tray icon, and want to have that be the only thing showing when the...
4
by: BrianDH | last post by:
Hi I have an application with 3 windows forms. One of which I load at startup but hide, then show/hide based on users click. How can I test to see if the windows is hidden, or is at the moment...
3
by: Gil | last post by:
on start up i have a form that opens but i want it to stay hidden. i tried a few things so far and i had no luck. i did : Private Sub Form_Load() me.visible = false End Sub Private Sub...
6
by: MJB | last post by:
I have an application that I need to hide at startup in the system tray. I found this article on how to do it:...
3
by: Raj Wall | last post by:
Hi, I have an application which, when running, is to be seen only in the system tray as a right-clickable icon. However I want the main Form window itself to immediately disappear without...
11
by: Nick 'The database Guy' | last post by:
Hi People, How do you go about hiding the database window. The reason for doing this is that sometimes have to manually add data to tables. I have a fully interatctive menu system from which...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.