472,136 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,136 software developers and data experts.

Closing event

I want to catch the Closing event for my form. I created a test windows app
using the wizard. I then create the Closing event by clicking the lightning
bolt on the properties pane. The code is added to the app but my app won't
compile. It generates a "Test.Form1.Closing() denotes a 'method' which is
not valid in the given context" error.
Nov 17 '05 #1
6 5557
Hi,

Check the following:

1) Check that you have a line on the Windows designer code like:

this.Closing += new
System.ComponentModel.CancelEventHandler(this.Form 1_Closing);

2) Note if the function "Form1_Closing" (the form1 will be the name of your
form) exists like

private void Form1_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
//Put your stuff here
}

I use to mess around with my events and remove the function when the
overloading is still there!. The wizard that creates the event can not handle
changes on its code :)

Salva
Hi,

Upon a string class lenght is set to UInt32, actually is not real, it has a
much limited number, I found a very interesting page about strings.

http://www.codeproject.com/dotnet/strings.asp

Anyway, back to your case, it seems that the message box has a limit on the
amount of data that can show, this seems to be normal, otherwise imaging a
hugh message box with 2Mb of string data!

Best regards
Salva
"Al the programmer" wrote:
I want to catch the Closing event for my form. I created a test windows app
using the wizard. I then create the Closing event by clicking the lightning
bolt on the properties pane. The code is added to the app but my app won't
compile. It generates a "Test.Form1.Closing() denotes a 'method' which is
not valid in the given context" error.

Nov 17 '05 #2
hi,

can you post the code in question, double click the closing event and this
will create the method you need and the hook needed.

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Al the programmer" <Al*************@discussions.microsoft.com> wrote in
message news:2A**********************************@microsof t.com...
I want to catch the Closing event for my form. I created a test windows
app
using the wizard. I then create the Closing event by clicking the
lightning
bolt on the properties pane. The code is added to the app but my app
won't
compile. It generates a "Test.Form1.Closing() denotes a 'method' which is
not valid in the given context" error.

Nov 17 '05 #3
Hi there,
the correct way of the event closing is:
private void TestForm_Closing(object sender,
System.ComponentModel.CancelEventArgs e)

{
}

in your post you don't have any arguments, so if the generator of VS have
some problem then copy and pasty the above function, and then go to the
events property window and intead of double-clicking the closing event just
dropDown the list and you will be able to assing the above function to the
event.

hope that helps

"Al the programmer" <Al*************@discussions.microsoft.com> wrote in
message news:2A**********************************@microsof t.com...
I want to catch the Closing event for my form. I created a test windows
app
using the wizard. I then create the Closing event by clicking the
lightning
bolt on the properties pane. The code is added to the app but my app
won't
compile. It generates a "Test.Form1.Closing() denotes a 'method' which is
not valid in the given context" error.

Nov 17 '05 #4
It appears Visual Studio is doing something wrong. All I am doing is
creating a Windows application and then adding a "Closing" event.

Visual Studio added the following code to InitializeComponent():
this.Closing += new System.ComponentModel.CancelEventHandler(this.Clos ing);

Visual Studio added the following function:
private void Closing(object sender, System.ComponentModel.CancelEventArgs e)

When I try to build I get the following error on the line that was added to
InitializeComponent(). 'Test.Form1.Closing(object,
System.ComponentModel.CancelEventArgs)' denotes a 'method' which is not valid
in the given context
"Al the programmer" wrote:
I want to catch the Closing event for my form. I created a test windows app
using the wizard. I then create the Closing event by clicking the lightning
bolt on the properties pane. The code is added to the app but my app won't
compile. It generates a "Test.Form1.Closing() denotes a 'method' which is
not valid in the given context" error.

Nov 17 '05 #5
Hi,

Can you send me that sample app to sa*********@yahoo.co.uk, I will have a
look and give you an answer

"Al the programmer" wrote:
It appears Visual Studio is doing something wrong. All I am doing is
creating a Windows application and then adding a "Closing" event.

Visual Studio added the following code to InitializeComponent():
this.Closing += new System.ComponentModel.CancelEventHandler(this.Clos ing);

Visual Studio added the following function:
private void Closing(object sender, System.ComponentModel.CancelEventArgs e)

When I try to build I get the following error on the line that was added to
InitializeComponent(). 'Test.Form1.Closing(object,
System.ComponentModel.CancelEventArgs)' denotes a 'method' which is not valid
in the given context
"Al the programmer" wrote:
I want to catch the Closing event for my form. I created a test windows app
using the wizard. I then create the Closing event by clicking the lightning
bolt on the properties pane. The code is added to the app but my app won't
compile. It generates a "Test.Form1.Closing() denotes a 'method' which is
not valid in the given context" error.

Nov 17 '05 #6
Hi,

You were calling the event handler function "Closing" and it was clashing
with the "Closing" delegate of the form. Changing the name solves the problem.

Regards
Salva
"Al the programmer" wrote:
It appears Visual Studio is doing something wrong. All I am doing is
creating a Windows application and then adding a "Closing" event.

Visual Studio added the following code to InitializeComponent():
this.Closing += new System.ComponentModel.CancelEventHandler(this.Clos ing);

Visual Studio added the following function:
private void Closing(object sender, System.ComponentModel.CancelEventArgs e)

When I try to build I get the following error on the line that was added to
InitializeComponent(). 'Test.Form1.Closing(object,
System.ComponentModel.CancelEventArgs)' denotes a 'method' which is not valid
in the given context
"Al the programmer" wrote:
I want to catch the Closing event for my form. I created a test windows app
using the wizard. I then create the Closing event by clicking the lightning
bolt on the properties pane. The code is added to the app but my app won't
compile. It generates a "Test.Form1.Closing() denotes a 'method' which is
not valid in the given context" error.

Nov 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Ron L | last post: by
1 post views Thread by Chris Bruce | last post: by
1 post views Thread by Chirag Malvi | last post: by
14 posts views Thread by =?Utf-8?B?UHVjY2E=?= | last post: by
19 posts views Thread by zacks | last post: by
reply views Thread by leo001 | last post: by

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.