Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 107,309 C# Programmers for FREE! Ask your question and get quick answers from experts. There are 2,044 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Adding event to form

 
Reply to this topicStart new topic

Adding event to form

killnine
post 8 Jul, 2008 - 11:19 AM
Post #1


D.I.C Head

**
Joined: 12 Feb, 2007
Posts: 104



Thanked 2 times
My Contributions


Hey guys,
I have a process that transfers data from one computer to another. When the process completes, I want to show, in a statusbar at the bottom of the screen, "Transfer Complete". However, after the user clicks anywhere on the application, I want the statusbar to then say "Idle".

This is because the transfer often takes a long time and people leave the computer and come back, but don't know if the transfer has completed successfully or not (well, the app would give an error if it failed, but my superiors want this feature).

I was thinking of adding an event for Click, so that the event would be set (+=) when the transfer completes, and when the user fires the event, it removes itself. See below:

CODE

toolStripStatusCurrentECU.Text = "Transfer Complete";
this.Click += new System.EventHandler(this.TransferStatus_Click);


Then, down in the code...

CODE

private void TransferStatus_Click(object sender, EventArgs e)
        {
            toolStripStatusCurrentECU.Text = "Idle";

            this.Click -= new System.EventHandler(this.TransferStatus_Click);            
        }



My problem is that the event never fires! Thoughts?
User is offlineProfile CardPM

Go to the top of the page


tody4me
post 9 Jul, 2008 - 11:47 AM
Post #2


only Jenny Craig makes thin clients...

Group Icon
Joined: 12 Apr, 2006
Posts: 979



Thanked 2 times

Dream Kudos: 100
My Contributions


Is all the processing done on the same form, or is it being called out to a worker class? Where is the call to hook up the event coming from?

This post has been edited by tody4me: 9 Jul, 2008 - 11:49 AM
User is online!Profile CardPM

Go to the top of the page

killnine
post 9 Jul, 2008 - 01:51 PM
Post #3


D.I.C Head

**
Joined: 12 Feb, 2007
Posts: 104



Thanked 2 times
My Contributions


QUOTE(tody4me @ 9 Jul, 2008 - 11:47 AM) *

Is all the processing done on the same form, or is it being called out to a worker class? Where is the call to hook up the event coming from?



It's all being done on one form. What I decided to do instead was use the TabControl's "TabIndexChange" or whatever it is called to detect when a user changes panes.

The problem with trying to detect ANY action, is that controls don't inherit events (nor would you want them too under most circumstances). Therefore, its really hard to detect ANY event on an application without lots of silly, extra code.

I have TONS of controls, so it isn't practical to wire up all my controls for that one event.
User is offlineProfile CardPM

Go to the top of the page

jacobjordan
post 9 Jul, 2008 - 02:38 PM
Post #4


class Me : Perfection

Group Icon
Joined: 11 Jun, 2008
Posts: 610



Thanked 14 times

Dream Kudos: 1325
My Contributions


For one thing, that sub will only fire if the actual form has been clicked, and not if one of its controls has. If you want it to fire if the form or any of its controls has been clicked, you will need to do a

csharp

Control.Click += new System.EventHandler(this.TransferStatus_Click);

for every control on the form. So, are you sure you are actually clicking on the form?
User is offlineProfile CardPM

Go to the top of the page

born2c0de
post 10 Jul, 2008 - 01:04 AM
Post #5


printf("I'm a %XR",195936478);

Group Icon
Joined: 26 Nov, 2004
Posts: 3,716



Thanked 20 times

Dream Kudos: 2800

Expert In: C, C++, VB, VB.NET, C#, Java, x86 Assembly, Win32 API, Reversing

My Contributions


It would be wiser to use Custom Events (use delegates) or a (even better...) BackgroundWorker object.

BackgroundWorker Objects are perfect for Asynchronous work such as file downloads.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 8/28/08 07:08AM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month