473,322 Members | 1,379 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.

Event handler probs.


I've not much experience of C#, so maybe someone can help me with this
little problem?

I've discovered that an event handler seems to be able to call methods
in its own class, but not in other classes even if they are 'in scope'
(if that is the correct term).

For instance:

private void button1_Click(object sender, EventArgs e)
{
label1.Text = "Do nothing!";
Program.pgm.doNothing();
}

If the 'doNothing' line is commented the method changes the text of the
label on clicking the button. If the 'doNothing' line is included the
program compiles but when the method is executed (as evidenced by
stepping through it), but on return the whole application closes, with
no errors. What am I missing?

Cheers,

Cliff

--

Have you ever noticed that if something is advertised as 'amusing' or
'hilarious', it usually isn't?
Jul 22 '07 #1
4 1242
What doNothing does? Most probably problem is in the code of this method.

"Enkidu" <en********@com.cliffp.comwrote in message
news:46********@news2.actrix.gen.nz...
>
I've not much experience of C#, so maybe someone can help me with this
little problem?

I've discovered that an event handler seems to be able to call methods in
its own class, but not in other classes even if they are 'in scope' (if
that is the correct term).

For instance:

private void button1_Click(object sender, EventArgs e)
{
label1.Text = "Do nothing!";
Program.pgm.doNothing();
}

If the 'doNothing' line is commented the method changes the text of the
label on clicking the button. If the 'doNothing' line is included the
program compiles but when the method is executed (as evidenced by stepping
through it), but on return the whole application closes, with no errors.
What am I missing?

Cheers,

Cliff

--

Have you ever noticed that if something is advertised as 'amusing' or
'hilarious', it usually isn't?

Jul 22 '07 #2
If the "whole application closes" there was most likely an unhandled
exception caused by the code in the "doNothing" method call, not anything
having to do with the event handler method code.
-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
bogMetaFinder: http://www.blogmetafinder.com

"Enkidu" wrote:
>
I've not much experience of C#, so maybe someone can help me with this
little problem?

I've discovered that an event handler seems to be able to call methods
in its own class, but not in other classes even if they are 'in scope'
(if that is the correct term).

For instance:

private void button1_Click(object sender, EventArgs e)
{
label1.Text = "Do nothing!";
Program.pgm.doNothing();
}

If the 'doNothing' line is commented the method changes the text of the
label on clicking the button. If the 'doNothing' line is included the
program compiles but when the method is executed (as evidenced by
stepping through it), but on return the whole application closes, with
no errors. What am I missing?

Cheers,

Cliff

--

Have you ever noticed that if something is advertised as 'amusing' or
'hilarious', it usually isn't?
Jul 22 '07 #3
Exactly what it says. There was originally no code between the open and
closing brackets, It now contains a bit of meaningless code!

public int doNothing()
{
int i = 3;
i++;
return i;
}

Cheers,

Cliff

AlexS wrote:
What doNothing does? Most probably problem is in the code of this method.

"Enkidu" <en********@com.cliffp.comwrote in message
news:46********@news2.actrix.gen.nz...
>I've not much experience of C#, so maybe someone can help me with this
little problem?

I've discovered that an event handler seems to be able to call methods in
its own class, but not in other classes even if they are 'in scope' (if
that is the correct term).

For instance:

private void button1_Click(object sender, EventArgs e)
{
label1.Text = "Do nothing!";
Program.pgm.doNothing();
}

If the 'doNothing' line is commented the method changes the text of the
label on clicking the button. If the 'doNothing' line is included the
program compiles but when the method is executed (as evidenced by stepping
through it), but on return the whole application closes, with no errors.
What am I missing?

--

Have you ever noticed that if something is advertised as 'amusing' or
'hilarious', it usually isn't?
Jul 23 '07 #4
Ah me! When I am debugging I often keep a 'doNothing' method around to
basically replace another method if I want to temporarily disable it. It
turns out that the 'doNothing' method actually works fine, but the
method it was standing in for demonstrates my problem. This indeed
points to a problem with my code in the original routine. Sorry for my
confusion.

The mystery is that I can step through the original method code (in C#
Express edition) and does exactly what I accused the 'doNothing' routine
of doing, in that it appears to 'return' normally to the event handler,
but when the event handler exits, the application closes (via a
'Dispose'). There appears to be no 'unhandled exception' or if there is,
I do not see it.

Sorry to have troubled you. Looks like I need to dig a little deeper.

Cheers,

Cliff

Peter Bromberg [C# MVP] wrote:
If the "whole application closes" there was most likely an unhandled
exception caused by the code in the "doNothing" method call, not anything
having to do with the event handler method code.

-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
bogMetaFinder: http://www.blogmetafinder.com

"Enkidu" wrote:
>I've not much experience of C#, so maybe someone can help me with this
little problem?

I've discovered that an event handler seems to be able to call methods
in its own class, but not in other classes even if they are 'in scope'
(if that is the correct term).

For instance:

private void button1_Click(object sender, EventArgs e)
{
label1.Text = "Do nothing!";
Program.pgm.doNothing();
}

If the 'doNothing' line is commented the method changes the text of the
label on clicking the button. If the 'doNothing' line is included the
program compiles but when the method is executed (as evidenced by
stepping through it), but on return the whole application closes, with
no errors. What am I missing?

--

Have you ever noticed that if something is advertised as 'amusing' or
'hilarious', it usually isn't?
Jul 23 '07 #5

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

Similar topics

10
by: tony kulik | last post by:
This code works fine in ie and opera but not at all in Mozilla. Anybody got a clue as to how to get it right? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <script...
18
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing the visible status of a form. I have some code...
8
by: Mark | last post by:
Hi, I'm looking for some ideas on how to build a very simple Event processing framework in my C++ app. Here is a quick background ... I'm building a multithreaded app in C++ (on Linux) that...
6
by: vbMark | last post by:
If I have a control, for example a CheckedListBox, how do I add and event to code, for example that a box has been checked by the user? Thanks
13
by: Charles Law | last post by:
Mr "yEaH rIgHt" posted the following link about a week ago in answer to my question about removing event handlers. > http://www.vbinfozine.com/t_bindevt.shtml Following on from that post, the...
3
by: Beth | last post by:
in the following: this.ExitButton.Click += new System.EventHandler(this.ExitButton_Click); if I saw an equation, such as y +=x; then y = y+x. But what is the meaning in the event handler. I...
5
by: Richard Grant | last post by:
Hi, I need to "save" in a variable the event handler sub of a control's event, then perform some process, and finally "restore" the originally saved event handler. Example in pseudo-code: 1)...
1
by: tdan | last post by:
I do not know how to get Event.stopObserving() to work in the context I am using it. I am displaying a Color Selection Table and attaching 2 events: 1. onmouseover to display the color to the user...
4
by: aamir | last post by:
Hello, I guess the subject line says it all. I have put Trace.Warn() in the SelectedIndexChanged event handler, but it does not get listed when the trace is on for that page. I have AutoPostback =...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
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...
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: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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: 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...

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.