473,387 Members | 1,512 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.

Form and "X" button

Hi,

How can I detect that a VS.NET2003 C# form is closed with the upper
right "X" button ?

This is because I want to add code to the myForm.OnClosing() event to do
a different process if a form is closed by the user (with the "X"
button) or if the form is closed with myForm.close().

Thank you!
Marty
Nov 17 '05 #1
8 9797
Set a global boolean variable (field), and write a method that does the
myForm.Close() work. The method would set the variable to indicate that the
method is closing the form. The OnClosing() mathod can then check that
variable (field) to find out whether the form was closed by your method or
not.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
A watched clock never boils.

"Marty" <xm******@hotmail.com> wrote in message
news:MMp7f.40670$yS6.33588@clgrps12...
Hi,

How can I detect that a VS.NET2003 C# form is closed with the upper right
"X" button ?

This is because I want to add code to the myForm.OnClosing() event to do a
different process if a form is closed by the user (with the "X" button) or
if the form is closed with myForm.close().

Thank you!
Marty

Nov 17 '05 #2
Marty,

When you make a call to Close, why not set a flag in your form which
indicates that it is you who made the call. Then, in the on closing event,
you can check the flag. If it is set, you closed the form, otherwise, the
user did it, and you can perform whatever action you need.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Marty" <xm******@hotmail.com> wrote in message
news:MMp7f.40670$yS6.33588@clgrps12...
Hi,

How can I detect that a VS.NET2003 C# form is closed with the upper right
"X" button ?

This is because I want to add code to the myForm.OnClosing() event to do a
different process if a form is closed by the user (with the "X" button) or
if the form is closed with myForm.close().

Thank you!
Marty

Nov 17 '05 #3
VJ
Here is a sample to check if X button is clicked...

public const int SC_CLOSE = 61536;

public const int WM_SYSCOMMAND = 274;

public bool _closeClick = false;

protected override void WndProc(ref Message m)

{

if ( m.Msg == WM_SYSCOMMAND && m.WParam.ToInt32() == SC_CLOSE )

{

this._closeClick = true;

}

base.WndProc (ref m);

}

private Form1_Closing(object sender, System.ComponentModel.CancelEventArgs
e)

{

if ( this._closeClick )

{

// X button clicked..

}

}

Sorry for the bad format.. my notepad is screwed up... and I had to paste it
directly from VS.NET code....

VJ

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:%2****************@tk2msftngp13.phx.gbl...
Marty,

When you make a call to Close, why not set a flag in your form which
indicates that it is you who made the call. Then, in the on closing
event, you can check the flag. If it is set, you closed the form,
otherwise, the user did it, and you can perform whatever action you need.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Marty" <xm******@hotmail.com> wrote in message
news:MMp7f.40670$yS6.33588@clgrps12...
Hi,

How can I detect that a VS.NET2003 C# form is closed with the upper right
"X" button ?

This is because I want to add code to the myForm.OnClosing() event to do
a different process if a form is closed by the user (with the "X" button)
or if the form is closed with myForm.close().

Thank you!
Marty


Nov 17 '05 #4
Hi VJ,

Thank you for your help :) Where can I find the definitions of constants
like WM_SYSCOMMAND and SC_CLOSE, maybe there are other const that I
could use for future process, I find them useful.

Thanks,
Marty

VJ wrote:
Here is a sample to check if X button is clicked...

public const int SC_CLOSE = 61536;

public const int WM_SYSCOMMAND = 274;

public bool _closeClick = false;

protected override void WndProc(ref Message m)

{

if ( m.Msg == WM_SYSCOMMAND && m.WParam.ToInt32() == SC_CLOSE )

{

this._closeClick = true;

}

base.WndProc (ref m);

}

private Form1_Closing(object sender, System.ComponentModel.CancelEventArgs
e)

{

if ( this._closeClick )

{

// X button clicked..

}

}

Sorry for the bad format.. my notepad is screwed up... and I had to paste it
directly from VS.NET code....

VJ

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:%2****************@tk2msftngp13.phx.gbl...
Marty,

When you make a call to Close, why not set a flag in your form which
indicates that it is you who made the call. Then, in the on closing
event, you can check the flag. If it is set, you closed the form,
otherwise, the user did it, and you can perform whatever action you need.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Marty" <xm******@hotmail.com> wrote in message
news:MMp7f.40670$yS6.33588@clgrps12...
Hi,

How can I detect that a VS.NET2003 C# form is closed with the upper right
"X" button ?

This is because I want to add code to the myForm.OnClosing() event to do
a different process if a form is closed by the user (with the "X" button)
or if the form is closed with myForm.close().

Thank you!
Marty



Nov 17 '05 #5
Thank you guys for your help :)
Have a nice day!
Marty

Marty wrote:
Hi,

How can I detect that a VS.NET2003 C# form is closed with the upper
right "X" button ?

This is because I want to add code to the myForm.OnClosing() event to do
a different process if a form is closed by the user (with the "X"
button) or if the form is closed with myForm.close().

Thank you!
Marty

Nov 17 '05 #6
C:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\PlatformSDK\Include\WinUser.h assuming you have VS.NET
Enterprise or VC++.

Jason Newell
Marty wrote:
Hi VJ,

Thank you for your help :) Where can I find the definitions of constants
like WM_SYSCOMMAND and SC_CLOSE, maybe there are other const that I
could use for future process, I find them useful.

Thanks,
Marty

VJ wrote:
Here is a sample to check if X button is clicked...

public const int SC_CLOSE = 61536;

public const int WM_SYSCOMMAND = 274;

public bool _closeClick = false;

protected override void WndProc(ref Message m)

{

if ( m.Msg == WM_SYSCOMMAND && m.WParam.ToInt32() == SC_CLOSE )

{

this._closeClick = true;

}

base.WndProc (ref m);

}

private Form1_Closing(object sender,
System.ComponentModel.CancelEventArgs e)

{

if ( this._closeClick )

{

// X button clicked..

}

}

Sorry for the bad format.. my notepad is screwed up... and I had to
paste it directly from VS.NET code....

VJ

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com>
wrote in message news:%2****************@tk2msftngp13.phx.gbl...
Marty,

When you make a call to Close, why not set a flag in your form
which indicates that it is you who made the call. Then, in the on
closing event, you can check the flag. If it is set, you closed the
form, otherwise, the user did it, and you can perform whatever action
you need.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Marty" <xm******@hotmail.com> wrote in message
news:MMp7f.40670$yS6.33588@clgrps12...

Hi,

How can I detect that a VS.NET2003 C# form is closed with the upper
right "X" button ?

This is because I want to add code to the myForm.OnClosing() event
to do a different process if a form is closed by the user (with the
"X" button) or if the form is closed with myForm.close().

Thank you!
Marty


Nov 17 '05 #7
Thank you :)
Marty

Jason Newell wrote:
C:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\PlatformSDK\Include\WinUser.h assuming you have VS.NET
Enterprise or VC++.

Jason Newell
Marty wrote:
Hi VJ,

Thank you for your help :) Where can I find the definitions of
constants like WM_SYSCOMMAND and SC_CLOSE, maybe there are other const
that I could use for future process, I find them useful.

Thanks,
Marty

VJ wrote:
Here is a sample to check if X button is clicked...

public const int SC_CLOSE = 61536;

public const int WM_SYSCOMMAND = 274;

public bool _closeClick = false;

protected override void WndProc(ref Message m)

{

if ( m.Msg == WM_SYSCOMMAND && m.WParam.ToInt32() == SC_CLOSE )

{

this._closeClick = true;

}

base.WndProc (ref m);

}

private Form1_Closing(object sender,
System.ComponentModel.CancelEventArgs e)

{

if ( this._closeClick )

{

// X button clicked..

}

}

Sorry for the bad format.. my notepad is screwed up... and I had to
paste it directly from VS.NET code....

VJ

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com>
wrote in message news:%2****************@tk2msftngp13.phx.gbl...

Marty,

When you make a call to Close, why not set a flag in your form
which indicates that it is you who made the call. Then, in the on
closing event, you can check the flag. If it is set, you closed the
form, otherwise, the user did it, and you can perform whatever
action you need.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Marty" <xm******@hotmail.com> wrote in message
news:MMp7f.40670$yS6.33588@clgrps12...

> Hi,
>
> How can I detect that a VS.NET2003 C# form is closed with the upper
> right "X" button ?
>
> This is because I want to add code to the myForm.OnClosing() event
> to do a different process if a form is closed by the user (with the
> "X" button) or if the form is closed with myForm.close().
>
> Thank you!
> Marty


Nov 17 '05 #8
VJ
Thanks Marty...

"Marty" <xm******@hotmail.com> wrote in message
news:vrs7f.60517$ir4.8954@edtnps90...
Thank you :)
Marty

Jason Newell wrote:
C:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\PlatformSDK\Include\WinUser.h assuming you have VS.NET
Enterprise or VC++.

Jason Newell
Marty wrote:
Hi VJ,

Thank you for your help :) Where can I find the definitions of constants
like WM_SYSCOMMAND and SC_CLOSE, maybe there are other const that I
could use for future process, I find them useful.

Thanks,
Marty

VJ wrote:

Here is a sample to check if X button is clicked...

public const int SC_CLOSE = 61536;

public const int WM_SYSCOMMAND = 274;

public bool _closeClick = false;

protected override void WndProc(ref Message m)

{

if ( m.Msg == WM_SYSCOMMAND && m.WParam.ToInt32() == SC_CLOSE )

{

this._closeClick = true;

}

base.WndProc (ref m);

}

private Form1_Closing(object sender,
System.ComponentModel.CancelEventArgs e)

{

if ( this._closeClick )

{

// X button clicked..

}

}

Sorry for the bad format.. my notepad is screwed up... and I had to
paste it directly from VS.NET code....

VJ

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com>
wrote in message news:%2****************@tk2msftngp13.phx.gbl...

> Marty,
>
> When you make a call to Close, why not set a flag in your form which
> indicates that it is you who made the call. Then, in the on closing
> event, you can check the flag. If it is set, you closed the form,
> otherwise, the user did it, and you can perform whatever action you
> need.
>
> Hope this helps.
>
>
> --
> - Nicholas Paldino [.NET/C# MVP]
> - mv*@spam.guard.caspershouse.com
>
> "Marty" <xm******@hotmail.com> wrote in message
> news:MMp7f.40670$yS6.33588@clgrps12...
>
>> Hi,
>>
>> How can I detect that a VS.NET2003 C# form is closed with the upper
>> right "X" button ?
>>
>> This is because I want to add code to the myForm.OnClosing() event to
>> do a different process if a form is closed by the user (with the "X"
>> button) or if the form is closed with myForm.close().
>>
>> Thank you!
>> Marty
>
>
>
>

Nov 17 '05 #9

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

Similar topics

7
by: PhilM | last post by:
perhaps I am just a little tired, but I am having trouble with my form buttons. Firstly I name them like this name=\"round".$counter."heats\" which results in variables $round1heats...
22
by: moocow | last post by:
Hi. I am using a background image in a form button. The problem I am having is that there is a 1 pixel margin inside the button on all sides. I would like my background image to fill the...
2
by: Bill Cherepy | last post by:
Is it possible to have a tooltip over a form button? I did a search, but no help. Thanks, Bill Cherepy Grayson, GA
2
by: harleyman1974 | last post by:
I need to programatically "click" a form button from a c++ or c# application which is found on a page. I need to post data to a page and have it interpret the post as a click occured, but I am...
4
by: ghadley_00 | last post by:
Hi, Can anyone recommend a piece of VBA code I could attach to a button in a MS Form form that will close the current form and bring the switchboard to foreground. I'm trying to integrate a form...
1
by: regelcom | last post by:
My son is trying to create an about form button for a form he has already created. Any help would be great. Thanks
5
by: plumba | last post by:
Ok, another query.... I have a checkbox at the bottom of my form which when checked unhides a <div> block which displays the submit button. The problem I have is when the clear form button is...
1
by: joshapalooza | last post by:
I am using a form to sort a report, but I can't seem to get the "clear form" button to work. I used the wizard when I installed the button, using the clear form option under the form option list....
2
by: Hulas | last post by:
Guys, I have two questions. (a) How do I add two fields of the same table to a single combo box. For example if I have two fields ID1 and ID2 in a table called Identification, than how should I...
3
by: KevinC | last post by:
Hi All, I have two tables: tblLicensedPrem and tblLicensedPremHistory (these tables are identical). tblLicensedPrem contains records for licensed premises. Over time details of a licensed...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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...

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.