473,888 Members | 1,564 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(obje ct sender, System.EventArg s e)
{
this.WindowStat e = 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 51729
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("user 32.dll")]
public static extern int SetWindowLong( IntPtr window, int index, int
value);

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

const int GWL_EXSTYLE = -20;
const int WS_EX_TOOLWINDO W = 0x00000080;
const int WS_EX_APPWINDOW = 0x00040000;

3. I copied this code in the Form1_Load method

this.WindowStat e = System.Windows. Forms.FormWindo wState.Minimize d;
this.Visible = false;
this.ShowInTask bar = false;
int windowStyle = GetWindowLong(H andle, GWL_EXSTYLE);
SetWindowLong(H andle, GWL_EXSTYLE, windowStyle | WS_EX_TOOLWINDO W);
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************ **@exisconsulti ng.com> wrote
in message news:e$******** ******@TK2MSFTN GP11.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************* *@exisconsultin g.com
"amil [c#newbie]" <am****@hotmail .com> wrote in message
news:%2******** ********@TK2MSF TNGP11.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(obje ct sender, System.EventArg s e)
{
this.WindowStat e = 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
74176
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 Form1.Visible = False Load (Form1)
9
2832
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: "You entered an expression that requires a form to be the active window". I have a popup form set to open when the DB is opened. On the open event of the form, I have the following code: fSetAccessWindow (SW_HIDE) as instructed on the web page....
5
2263
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 form won't hide itself. This is the main form of the application.
4
9175
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 program starts. Matthew
4
1565
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 being shown? Thanks BrianDH
3
18879
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 Form_Open(Cancel As Integer) me.visible = false end sub
6
14173
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: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtsksettingformtobeinvisibleatitsinception.asp The problem with this method is that when I call the Hide() function on f1 it causes the form to close which exits the app. Any other approaches to hiding the form at startup would be appreciated. Thanks
3
3346
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 having to be minimized. I have tried putting this.Hide(); in the Load method, but that doesn't work (the form still comes up and needs
11
7333
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 you can show the 'database window', the same button that you have to press to show the database window opens a small modal form which has one button which will return you to the menu system, but I also want it to close the database window!
0
9961
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9800
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11182
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10439
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7990
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7148
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5824
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6014
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3252
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.