473,847 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 47331
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.ToInt3 2 = SC_MINIMIZE Then
'User clicked "minimize"
Debug.WriteLine ("Minimizing... ")
ElseIf m.WParam.ToInt3 2 = 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.EventArg s)
MyBase.OnResize (e)
Select Case Me.WindowState
Case FormWindowState .Normal
MessageBox.Show ("Form was restored",
Application.Pro ductName)
Case FormWindowState .Minimized
MessageBox.Show ("Form was minimized",
Application.Pro ductName)
Case FormWindowState .Maximized
MessageBox.Show ("Form was maximized",
Application.Pro ductName)
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******@hotma il.com> wrote in message
news:uR******** ******@TK2MSFTN GP09.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.EventArg s)
MyBase.OnResize (e)
Select Case Me.WindowState
Case FormWindowState .Normal
MessageBox.Show ("Form was restored",
Application.Pro ductName)


What happens if the user really resizes the form?

Cheers

Arne Janning
Nov 23 '05 #5
"Arne Janning" <sp************ ***********@gma il.com> schrieb:
I normally simply handle the Resize event.

Something like:

Protected Overrides Sub OnResize(ByVal e As System.EventArg s)
MyBase.OnResize (e)
Select Case Me.WindowState
Case FormWindowState .Normal
MessageBox.Show ("Form was restored",
Application.Pro ductName)


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.EventArg s)
MyBase.OnResize (e)
Select Case Me.WindowState
Case FormWindowState .Normal
MessageBox.Show ("Form was restored",
Application.Pro ductName)
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.Pro ductName)

;-)

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Arne Janning" <sp************ ***********@gma il.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.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.EventArg s)
| > MyBase.OnResize (e)
| > Select Case Me.WindowState
| > Case FormWindowState .Normal
| > MessageBox.Show ("Form was restored",
| > Application.Pro ductName)
|
| 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******** ******@TK2MSFTN GP09.phx.gbl...
| "Arne Janning" <sp************ ***********@gma il.com> schrieb:
| >> I normally simply handle the Resize event.
| >>
| >> Something like:
| >>
| >> Protected Overrides Sub OnResize(ByVal e As System.EventArg s)
| >> MyBase.OnResize (e)
| >> Select Case Me.WindowState
| >> Case FormWindowState .Normal
| >> MessageBox.Show ("Form was restored",
| >> Application.Pro ductName)
| >
| > 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
4037
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 form load event, but I don't see any significant drop in memory usage. Anybody know why? Thanks, Bhargavan
2
11776
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 maximized. I tried to test these 2 codes below: 1.
1
2902
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 my child forms as false & the respective minimize & maximize box property to false, i get the control box with restore button as enabled (when i dock my child form in the MDI form with dockstyle as fill) which restores the
3
5443
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 remains visible (albeit completely disabled).
4
2681
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. i kno how to put it on the tray but how do i catch when its been minimized? thanks -- -iwdu15
9
1737
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 got a DOS box that showed some progress info. I then decided to add a form... So I made a new application and started with creating the form. Then I copied and pasted cpp code into places where I thought they should go - leaving out the stuff...
7
9337
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
5086
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 catch the event that is trigged when the little underscore(the minimize icon) up to the right is clicked. I need to catch this event because all my child window forms must also be minimized
2
4964
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 datagridview within VB2005. I validate the values in the row when the user leaves the row via the grid's RowValidating event. I want to allow the user to exit the application by clicking the "x".
0
9892
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
9734
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
10995
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
10347
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...
0
9493
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7888
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
5915
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4130
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3168
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.