By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,222 Members | 1,099 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,222 IT Pros & Developers. It's quick & easy.

catch minimization

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
jdm
=?Utf-8?B?aXdkdTE1?= <iw****@discussions.microsoft.com> wrote in
news:B3**********************************@microsof t.com:
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
Nov 21 '05 #2

P: n/a
awsome thanks
Nov 21 '05 #3

P: n/a
"jdm" <nu**@invalid.com> schrieb:
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
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #4

P: n/a
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
"iwdu15" <iw****@discussions.microsoft.com> wrote in message
news:B3**********************************@microsof t.com...
| 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
Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.