473,387 Members | 1,420 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,387 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 7907
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.