Form resizing error...

b3jsd73jfx

Active member
Joined
Mar 6, 2006
Messages
28
Programming Experience
1-3
I have a program made that, when minimizes it hides the form, removes it from the taskbar. If I double click the tray icon (which is always visible), the form unhides. To make it work properly, I had to make it so that when the program minimizes, the program hides and then maximizes itself again while staying hidden (it wouldn't work the other way for some reason, it would only show the upper left hand corner of the title bar). Here's the code I use currently:
VB.NET:
[SIZE=2][COLOR=#0000ff]Private [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] Form1_SizeChanged([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Object[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]MyBase[/COLOR][/SIZE][SIZE=2].SizeChanged
[/SIZE][SIZE=2][COLOR=#008000]'If the window is minimized then
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].WindowState = FormWindowState.Minimized [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]'Hide me
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].Visible = [/SIZE][SIZE=2][COLOR=#0000ff]False
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]'Restore the window so it doesn't show up in the Alt+Tab list
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].WindowState = FormWindowState.Normal
[/SIZE][SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Private [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] tskIcon_DoubleClick([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Object[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] tskIcon.DoubleClick
[/SIZE][SIZE=2][COLOR=#008000]'Minimize the form so it knows to load up
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].WindowState = FormWindowState.Minimized
[/SIZE][SIZE=2][COLOR=#008000]'Show me
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].Visible = [/SIZE][SIZE=2][COLOR=#0000ff]True
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]'Restore the window to normal
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].WindowState = FormWindowState.Normal
[/SIZE][SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
Now i'm trying to add a "Start in system tray" option to the program. It stores a boolean value (True/False) in a text file along with about 10 other lines of values. When the program is started, it opens the text files, reads the values into their corresponding variables, and then goes from there. If the "Start in system tray" variable is true, I just have it run the minimize code by doing a Me.WindowState = FormWindowState.Minimized. But it won't minimize when I do that. Any suggestions or even better code to handle the system tray aspect?
 
The form won't minimize or the event doesn't fire? . My suggestion, don't do it in the form size changed event. Add your own events to the form,and raise the events accordingly to handle want you want it to do to.
 
Back
Top