473,465 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Capturing onMinimize event?

Jim
Hi,

I intend to set the form Visibility to false and show a taskbar icon
instead. I've done this on the FormClosing event but I want this to
happen when the form is minized too.

How do I capture this event?

Thanks in advance,
Mikhail
Nov 16 '05 #1
6 7911
On Wed, 07 Apr 2004 17:11:39 +0530, Jim wrote:
I intend to set the form Visibility to false and show a taskbar icon
instead. I've done this on the FormClosing event but I want this to
happen when the form is minized too.


declare the following somewhere in your form:

public event EventHandler Minimize;

and inside the constructor of your form, attach an event handler:

this.Minimize += new EventHandler(this.Form1_Minimize);

and finally, copy/paste this method to your form:

protected override void WndProc(ref Message msg) {
const int WM_SIZE = 0x0005;
const int SIZE_MINIMIZED = 1;

if ((msg.Msg == WM_SIZE) && ((int) msg.WParam == SIZE_MINIMIZED) &&
(this.Minimize != null)) {
this.Minimize(this, EventArgs.Empty);
}

base.WndProc(ref msg);
}

--
Asbjørn Ulsberg -=|=- as******@hotmail.com
"He's a loathsome offensive brute, yet I can't look away"
Nov 16 '05 #2
Jim
Works beautifully!

Thanks :-)

Asbjørn Ulsberg wrote:
On Wed, 07 Apr 2004 17:11:39 +0530, Jim wrote:
I intend to set the form Visibility to false and show a taskbar icon
instead. I've done this on the FormClosing event but I want this to
happen when the form is minized too.

declare the following somewhere in your form:

public event EventHandler Minimize;

and inside the constructor of your form, attach an event handler:

this.Minimize += new EventHandler(this.Form1_Minimize);

and finally, copy/paste this method to your form:

protected override void WndProc(ref Message msg) {
const int WM_SIZE = 0x0005;
const int SIZE_MINIMIZED = 1;

if ((msg.Msg == WM_SIZE) && ((int) msg.WParam == SIZE_MINIMIZED) &&
(this.Minimize != null)) {
this.Minimize(this, EventArgs.Empty);
}

base.WndProc(ref msg);
}

Nov 16 '05 #3
Hi,

Don't You know where i can search for integer representation
of Window messages and WParams?

Marcin
On Wed, 07 Apr 2004 17:11:39 +0530, Jim wrote:
I intend to set the form Visibility to false and show a taskbar icon
instead. I've done this on the FormClosing event but I want this to
happen when the form is minized too.

declare the following somewhere in your form:

public event EventHandler Minimize;

and inside the constructor of your form, attach an event handler:

this.Minimize += new EventHandler(this.Form1_Minimize);

and finally, copy/paste this method to your form:

protected override void WndProc(ref Message msg) {
const int WM_SIZE = 0x0005;
const int SIZE_MINIMIZED = 1;

if ((msg.Msg == WM_SIZE) && ((int) msg.WParam == SIZE_MINIMIZED) &&
(this.Minimize != null)) {
this.Minimize(this, EventArgs.Empty);
}

base.WndProc(ref msg);
}


Nov 16 '05 #4
On Wed, 07 Apr 2004 15:02:38 +0200, Marcin Grzębski wrote:
Don't You know where i can search for integer representation
of Window messages and WParams?


No, sorry. I found the example on The Code Project or something.

--
Asbjørn Ulsberg -=|=- as******@hotmail.com
"He's a loathsome offensive brute, yet I can't look away"
Nov 16 '05 #5
Actually, when the form is minimized a Form.Resize event is fired...
You can then check the WindowState property wether the form is
minimized in the event handler...
this.Resize += new EventHandler(HideForm);
[code:1:ba4f873ece]
void HideForm(object sender, EventArgs e)
{
if(this.WindowState == FormWindowState.Minimized)
{
// put your code here...
}
}
[/code:1:ba4f873ece]

read more about the FormWindowState enumeration here...

http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemWindowsFormsFormWindowStateClassTopic.a sp?frame=true

Nov 16 '05 #6
Actually, when the form is minimized a Form.Resize event is fired...
You can then check the WindowState property wether the form is
minimized in the event handler...
this.Resize += new EventHandler(HideForm);
[code:1:ba4f873ece]
void HideForm(object sender, EventArgs e)
{
if(this.WindowState == FormWindowState.Minimized)
{
// put your code here...
}
}
[/code:1:ba4f873ece]

read more about the FormWindowState enumeration here...

http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemWindowsFormsFormWindowStateClassTopic.a sp?frame=true

Nov 16 '05 #7

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

Similar topics

0
by: Joecx | last post by:
I am capturing the click event using Overrides OnClick. This captures the click event in the open or unused areas of the form, but it doesn't capture the click event in the textboxes etc. Do I...
3
by: Greg | last post by:
I want to be able to capture the user pressing Ctrl+S. I know that the IE browser has a key binding for Ctrl+S but is there any way that I can be notified of this key press anyway. I have found...
3
by: Jim | last post by:
Hi, I intend to set the form Visibility to false and show a taskbar icon instead. I've done this on the FormClosing event but I want this to happen when the form is minized too. How do I...
10
by: Andrew | last post by:
Hi, I have a messagebox that pops up due to an event. I did it in javascript. ie. alert("Time's up. Assessment Ended"); I want to capture the OK and Cancel events of this alert messagebox. My...
5
by: Nick | last post by:
Hey guys, I have 2 events on a windows forms datagrid, the mouse move as well as the double click events. What's happening is that when I double click on a row in the grid, the mouse move event...
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
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...
1
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
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...
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
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.