catch minimization

G

Guest

hi, how can i catch when the user clicks the minimize button on the form and
do a certain event then? what im looking to do is when the user minimizes the
form, to put the form on the system tray. i kno how to put it on the tray but
how do i catch when its been minimized? thanks
 
J

jdm

hi, how can i catch when the user clicks the minimize button on the
form and do a certain event then? what im looking to do is when the
user minimizes the form, to put the form on the system tray. i kno how
to put it on the tray but how do i catch when its been minimized?
thanks

there's an example here
http://www.visualbasicforum.com/showthread.php?t=241017

:

Protected Overrides Sub WndProc(ByRef m As _
System.Windows.Forms.Message)
Const WM_SYSCOMMAND As Long = &H112
Const SC_MINIMIZE As Long = &HF020&
Const SC_MAXIMIZE As Long = &HF030&
' See if this is WM_SYSCOMMAND.
If m.Msg = WM_SYSCOMMAND Then
' Ignore SC_MINIMIZE and SC_MAXIMIZE commands.
If (m.WParam.ToInt32 And &HFFF0&) = SC_MINIMIZE Then
MsgBox("Can't Minimize!!")
Exit Sub
End If
If (m.WParam.ToInt32 And &HFFF0&) = SC_MAXIMIZE Then
MsgBox("Can't Maximize!!")
Exit Sub
End If
End If
MyBase.WndProc(m)
End Sub
 
H

Herfried K. Wagner [MVP]

jdm said:
Protected Overrides Sub WndProc(ByRef m As _
System.Windows.Forms.Message)
Const WM_SYSCOMMAND As Long = &H112
Const SC_MINIMIZE As Long = &HF020&
Const SC_MAXIMIZE As Long = &HF030&

Note that 'Long' is a 64-bit datatype in VB.NET. Thus you'll have to change
the longs to ints:

\\\
Private Const WM_SYSCOMMAND As Int32 = &H112

Private Const SC_MAXIMIZE As Int32 = &HF030
Private Const SC_MINIMIZE As Int32 = &HF020
Private Const SC_RESTORE As Int32 = &HF120
Private Const SC_CLOSE As Int32 = &HF060

Protected Overrides Sub WndProc(ByRef m As Message)
If m.Msg = WM_SYSCOMMAND Then
Select Case m.WParam.ToInt32()
Case SC_MAXIMIZE
Debug.WriteLine("Form gets maximized.")
Case SC_MINIMIZE
Debug.WriteLine("Form gets minimized.")
Case SC_RESTORE
Debug.WriteLine("Form gets restored.")
Case SC_CLOSE
Debug.WriteLine("Form gets closed.")
End Select
End If
MyBase.WndProc(m)
End Sub
///
 
J

Jay B. Harlow [MVP - Outlook]

iwdu15,
In addition to the other comments.

I normally simply handle the Resize event.

Something like:

Protected Overrides Sub OnResize(ByVal e As System.EventArgs)
MyBase.OnResize(e)
Select Case Me.WindowState
Case FormWindowState.Normal
MessageBox.Show("Form was restored",
Application.ProductName)
Case FormWindowState.Minimized
MessageBox.Show("Form was minimized",
Application.ProductName)
Case FormWindowState.Maximized
MessageBox.Show("Form was maximized",
Application.ProductName)
End Select
End Sub


--
Hope this helps
Jay [MVP - Outlook]
T.S. Bradley - http://www.tsbradley.net


| hi, how can i catch when the user clicks the minimize button on the form
and
| do a certain event then? what im looking to do is when the user minimizes
the
| form, to put the form on the system tray. i kno how to put it on the tray
but
| how do i catch when its been minimized? thanks
| --
| -iwdu15
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top