473,417 Members | 1,406 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

How to catch a form minimize event?

I want to minimize my program to the tray when minimized. But there's no
"minimize" event. So how can I catch this event and use it?
Nov 23 '05 #1
8 47117
Hi Terry!

Terry Olsen wrote:
I want to minimize my program to the tray when minimized. But
there's no "minimize" event. So how can I catch this event and use
it?


You have to override WndProc:

Const WM_SYSCOMMAND As Int32 = &H112
Const SC_MINIMIZE As Int32 = &HF020
Const SC_RESTORE As Int32 = &HF120

Protected Overrides Sub WndProc(ByRef m As Message)
If m.Msg = WM_SYSCOMMAND Then
If m.WParam.ToInt32 = SC_MINIMIZE Then
'User clicked "minimize"
Debug.WriteLine("Minimizing...")
ElseIf m.WParam.ToInt32 = SC_RESTORE Then
'Restoring
Debug.WriteLine("Restoring...")
End If
End If
MyBase.WndProc(m)
End Sub

Cheers

Arne Janning
Nov 23 '05 #2
Hi Terry. Use can use Resize event. Example:

Dim f As Form
f = sender

'Check if the form is minimized
If f.WindowState = FormWindowState.Minimized Then
' the form has been minimized, insert your code here
End If

Regards, Thi.

Nov 23 '05 #3
Terry,
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]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Terry Olsen" <to******@hotmail.com> wrote in message
news:uR**************@TK2MSFTNGP09.phx.gbl...
|I want to minimize my program to the tray when minimized. But there's no
| "minimize" event. So how can I catch this event and use it?
|
|
Nov 23 '05 #4
Hi Jay!

Jay B. Harlow [MVP - Outlook] wrote:
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)


What happens if the user really resizes the form?

Cheers

Arne Janning
Nov 23 '05 #5
"Arne Janning" <sp***********************@gmail.com> schrieb:
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)


What happens if the user really resizes the form?


A messagebox is shown and resizing stops... In .NET 2.0 forms have
additional 'ResizeBegin' and 'ResizeEnd' events.

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

Nov 23 '05 #6
Hi Herfried!

Herfried K. Wagner [MVP] wrote:
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)
What happens if the user really resizes the form?


A messagebox is shown and resizing stops...


Agreed.
In .NET 2.0 forms have
additional 'ResizeBegin' and 'ResizeEnd' events.


So now you can decide whether you want to show that "Restoring"-MessageBox
at the beginning or the end of resizing ;-)

SCNR

Cheers

Arne Janning
Nov 23 '05 #7
Arne,
(I thought I sent this last night, if this is a double post)

The window state will continue to be Normal.

If you prefer:

| > Case FormWindowState.Normal
| > MessageBox.Show("Form was restored or resized",
| > Application.ProductName)

;-)

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Arne Janning" <sp***********************@gmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
| Hi Jay!
|
| Jay B. Harlow [MVP - Outlook] wrote:
| > 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)
|
| What happens if the user really resizes the form?
|
| Cheers
|
| Arne Janning
|
|
Nov 23 '05 #8
Herfried,
I would have expected Resizing & Resized events, so as to comply with the
"Framework Design Guidelines", although ResizeBegin & ResizeEnd sound
slightly better...

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:uU**************@TK2MSFTNGP09.phx.gbl...
| "Arne Janning" <sp***********************@gmail.com> schrieb:
| >> 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)
| >
| > What happens if the user really resizes the form?
|
| A messagebox is shown and resizing stops... In .NET 2.0 forms have
| additional 'ResizeBegin' and 'ResizeEnd' events.
|
| --
| M S Herfried K. Wagner
| M V P <URL:http://dotnet.mvps.org/>
| V B <URL:http://classicvb.org/petition/>
|
Nov 23 '05 #9

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

Similar topics

7
by: Bhargavan | last post by:
Hey Group, When I minimize and then maximize a form (in windows application), I see a significant drop in memory usuage in the task manager. I tried to do the same thing programatically during the...
2
by: Hide | last post by:
hi, Now, I'm creating window based applicaton. In this application, I want to put some traps(code) before form minimizing or maximizing event, but I only can get events after form minimized or...
1
by: Sumit | last post by:
Hi all, I have an MDI form in which i open some other forms. I dont want the Control Box (having minimize, restore/maximize and close button) Even though I have set the controlbox property of...
3
by: Don | last post by:
If you have a form that calls another form via the following code: Dim myForm as Form2 myForm = New Form2 myForm.Owner = Me MyForm.ShowDialog and you minimize the second form, the first form...
4
by: iwdu15 | last post by:
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....
9
by: Piccolo Pete | last post by:
This is a bit "wordy", but here is the scoop. I'm using Microsoft Visual Studio for VC++ in Windows 2000. I made an application which had no form in it. So when I ran the application, I just...
7
by: Lee | last post by:
Hi, How do I detect when a form is minimizing? specifically when a user clicks the show desktop button on the taskbar, rather than the minimize button on a form. thanks in advance
2
by: tony | last post by:
Hello! I have a mainManu where I can chose to display some window forms. When the mainMenu is minimized I need to minimize every window form that is started from the mainMenu. So I need to...
2
by: =?Utf-8?B?TG9zdEluTUQ=?= | last post by:
Hi All, I am trying to determine if the user clicked the "x" close button within the controlbox of the form (top right corner - next to minimize and maximize buttons). I am using the...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...
0
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...

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.