473,322 Members | 1,522 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,322 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 7900
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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.