Click here to Skip to main content
15,890,123 members
Home / Discussions / C#
   

C#

 
GeneralRe: C# console application to dll and register..... Pin
Dave Kreskowiak14-Oct-09 8:59
mveDave Kreskowiak14-Oct-09 8:59 
GeneralRe: C# console application to dll and register..... Pin
greendragons14-Oct-09 9:04
greendragons14-Oct-09 9:04 
QuestionProblem changing text on from lable from another class [modified] Pin
yogi_bear_7914-Oct-09 6:20
yogi_bear_7914-Oct-09 6:20 
AnswerRe: Problem changing text on from lable from another class Pin
Dave Kreskowiak14-Oct-09 6:38
mveDave Kreskowiak14-Oct-09 6:38 
GeneralRe: Problem changing text on from lable from another class Pin
yogi_bear_7914-Oct-09 8:02
yogi_bear_7914-Oct-09 8:02 
GeneralRe: Problem changing text on from lable from another class Pin
DaveyM6914-Oct-09 8:05
professionalDaveyM6914-Oct-09 8:05 
GeneralRe: Problem changing text on from lable from another class Pin
yogi_bear_7914-Oct-09 8:42
yogi_bear_7914-Oct-09 8:42 
GeneralRe: Problem changing text on from lable from another class Pin
DaveyM6914-Oct-09 9:05
professionalDaveyM6914-Oct-09 9:05 
Then you have something wrong with your event raising, subscription or handling. You need to learn/understand how these work to use them successfully.

Here is a brief code snippet with comments which should give you an overview. If this isn't enough, google or search here on CodeProject... there are lots of articles/blogs on it. I even have an article on here covering this subject in some depth - Events Made Simple[^]
C#
public class TestClass
{
    /// <summary>
    /// Field to hold class instance.
    /// </summary>
    private ClassWithEvent classWithEvent;

    /// <summary>
    /// Initializes a new intance of TestClass.
    /// </summary>
    public TestClass()
    {
        // Instanciate classWithEvent
        classWithEvent = new ClassWithEvent();
        // Subscribe to the classWithEvent.Event, the method in brackets will be called when it is raised
        classWithEvent.Event += new EventHandler(classWithEvent_Event);
    }

    /// <summary>
    /// Method called when classWithEvent.Event is raised
    /// </summary>
    /// <param name="sender">The ClassWithEvent instance that raised the event.</param>
    /// <param name="e">The EventArgs instance that was sent with the event.</param>
    void classWithEvent_Event(object sender, EventArgs e)
    {
        // Do what you need to do here!
        Console.WriteLine("Event Rased!");
    }
}

public class ClassWithEvent
{
    /// <summary>
    /// This is the event!
    /// </summary>
    public event EventHandler Event;

    /// <summary>
    /// This method actually raises the event.
    /// </summary>
    /// <param name="e">The arguments class that holds any data relating to the event.</param>
    protected virtual void OnEvent(EventArgs e)
    {
        // Create a copy...
        EventHandler eh = Event;
        // Null check as eh will be null if no subscribers
        if (eh != null)
            eh(this, e);
    }

    /// <summary>
    /// This public method is just by way of example. This could be any method, property setter etc...
    /// </summary>
    public void PerformEvent()
    {
        // Call the method that actually raises the event
        OnEvent(EventArgs.Empty);
    }
}


Dave

Generic BackgroundWorker - My latest article!
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Why are you using VB6? Do you hate yourself? (Christian Graus)

GeneralRe: Problem changing text on from lable from another class Pin
yogi_bear_7914-Oct-09 10:17
yogi_bear_7914-Oct-09 10:17 
QuestionPerform a mouse click Pin
p3rson14-Oct-09 6:11
p3rson14-Oct-09 6:11 
AnswerRe: Perform a mouse click Pin
Keith Barrow14-Oct-09 6:24
professionalKeith Barrow14-Oct-09 6:24 
AnswerRe: Perform a mouse click Pin
Luc Pattyn14-Oct-09 6:36
sitebuilderLuc Pattyn14-Oct-09 6:36 
QuestionCreate Singleton Class Different AppDomain Pin
dataminers14-Oct-09 5:36
dataminers14-Oct-09 5:36 
AnswerRe: Create Singleton Class Different AppDomain Pin
Not Active14-Oct-09 6:09
mentorNot Active14-Oct-09 6:09 
GeneralRe: Create Singleton Class Different AppDomain Pin
dataminers14-Oct-09 10:25
dataminers14-Oct-09 10:25 
GeneralRe: Create Singleton Class Different AppDomain Pin
Not Active14-Oct-09 10:50
mentorNot Active14-Oct-09 10:50 
GeneralRe: Create Singleton Class Different AppDomain Pin
dataminers14-Oct-09 12:02
dataminers14-Oct-09 12:02 
GeneralRe: Create Singleton Class Different AppDomain Pin
Not Active14-Oct-09 14:40
mentorNot Active14-Oct-09 14:40 
GeneralRe: Create Singleton Class Different AppDomain Pin
dataminers14-Oct-09 21:20
dataminers14-Oct-09 21:20 
GeneralRe: Create Singleton Class Different AppDomain Pin
Keith Barrow14-Oct-09 22:59
professionalKeith Barrow14-Oct-09 22:59 
GeneralRe: Create Singleton Class Different AppDomain Pin
dataminers15-Oct-09 0:47
dataminers15-Oct-09 0:47 
QuestionExcel and C# Pin
antsims14-Oct-09 5:14
antsims14-Oct-09 5:14 
AnswerRe: Excel and C# Pin
Dave Kreskowiak14-Oct-09 5:21
mveDave Kreskowiak14-Oct-09 5:21 
GeneralRe: Excel and C# Pin
antsims14-Oct-09 6:22
antsims14-Oct-09 6:22 
GeneralRe: Excel and C# Pin
Dave Kreskowiak14-Oct-09 6:35
mveDave Kreskowiak14-Oct-09 6:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.