473,395 Members | 1,668 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,395 software developers and data experts.

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 7908
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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...

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.