Click here to Skip to main content
15,913,408 members
Home / Discussions / C#
   

C#

 
Questionevent handler Pin
nelsonpaixao31-Oct-08 13:37
nelsonpaixao31-Oct-08 13:37 
AnswerRe: event handler Pin
Mark Salsbery31-Oct-08 15:06
Mark Salsbery31-Oct-08 15:06 
GeneralRe: event handler Pin
#realJSOP1-Nov-08 0:34
professional#realJSOP1-Nov-08 0:34 
GeneralRe: event handler Pin
Nicholas Butler1-Nov-08 3:19
sitebuilderNicholas Butler1-Nov-08 3:19 
GeneralRe: event handler Pin
#realJSOP1-Nov-08 3:49
professional#realJSOP1-Nov-08 3:49 
GeneralRe: event handler Pin
DaveyM691-Nov-08 4:48
professionalDaveyM691-Nov-08 4:48 
AnswerRe: event handler Pin
PIEBALDconsult31-Oct-08 15:32
mvePIEBALDconsult31-Oct-08 15:32 
AnswerRe: event handler Pin
DaveyM691-Nov-08 0:20
professionalDaveyM691-Nov-08 0:20 
Everything the others have said. Also, Microsoft recommend (and use themselves) a copy to handle the possibility of the event becoming null after the null check but before it's raised. This is the way I implement something like this:
using System;

public class MyPage
{
    // use EventHandler<TEventArgs> for maintenance simplicity
    public event EventHandler<PageMenuInfoChangedEventArgs> PageMenuInfoChanged;
    // private variable
    private object _PageMenuInfo;
    // public property
    public object PageMenuInfo
    {
        get { return _PageMenuInfo; }
        set
        {
            if (_PageMenuInfo != value)
            {
                _PageMenuInfo = value;
                // pass event args to method
                OnPageMenuInfoChanged(new PageMenuInfoChangedEventArgs("Changed!"));
            }
        }
    }
    protected virtual void OnPageMenuInfoChanged(PageMenuInfoChangedEventArgs e)
    {
        // copy event
        EventHandler<PageMenuInfoChangedEventArgs> eh = PageMenuInfoChanged;
        if (eh != null)
            // raise event using standard pattern
            eh(this, e);
    }
}
public class PageMenuInfoChangedEventArgs : EventArgs
{
    public PageMenuInfoChangedEventArgs(string message)
    {
        _Message = message;
    }
    private string _Message;
    public string Message
    {
        get { return _Message; }
    }
}


Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)

GeneralRe: event handler Pin
nelsonpaixao3-Nov-08 12:48
nelsonpaixao3-Nov-08 12:48 
QuestionCan some body tell me why it behaves like this Pin
netJP12L31-Oct-08 11:14
netJP12L31-Oct-08 11:14 
QuestionActivating last textbox in DataGridView on form active Pin
AndrusM31-Oct-08 10:37
AndrusM31-Oct-08 10:37 
QuestionCancel the transformMatrix in Graphics Pin
baranils31-Oct-08 9:58
baranils31-Oct-08 9:58 
QuestionWindow as seperate thread. Pin
vaseeem31-Oct-08 9:52
vaseeem31-Oct-08 9:52 
GeneralRe: Window as seperate thread. Pin
Luc Pattyn31-Oct-08 10:40
sitebuilderLuc Pattyn31-Oct-08 10:40 
QuestionNewbie Property Binding Question Pin
Chris Klepeis31-Oct-08 9:50
Chris Klepeis31-Oct-08 9:50 
QuestionLooking for C# example to create Image Metadata app [modified] Pin
DrGerm31-Oct-08 9:35
DrGerm31-Oct-08 9:35 
QuestionFtpWebRequest Upload question Pin
KaptinKrunch31-Oct-08 8:38
KaptinKrunch31-Oct-08 8:38 
Questionhow to retreive correct control.visible property of a hidden control in c# Pin
Dino2Dino31-Oct-08 8:32
Dino2Dino31-Oct-08 8:32 
AnswerRe: how to retreive correct control.visible property of a hidden control in c# Pin
EliottA31-Oct-08 9:50
EliottA31-Oct-08 9:50 
AnswerRe: how to retreive correct control.visible property of a hidden control in c# Pin
Giorgi Dalakishvili31-Oct-08 11:45
mentorGiorgi Dalakishvili31-Oct-08 11:45 
GeneralRe: how to retreive correct control.visible property of a hidden control in c# Pin
Luc Pattyn31-Oct-08 12:21
sitebuilderLuc Pattyn31-Oct-08 12:21 
QuestionRe: how to retreive correct control.visible property of a hidden control in c# Pin
nelsonpaixao31-Oct-08 13:49
nelsonpaixao31-Oct-08 13:49 
AnswerRe: how to retreive correct control.visible property of a hidden control in c# Pin
Dave Kreskowiak1-Nov-08 5:20
mveDave Kreskowiak1-Nov-08 5:20 
QuestionList<int> in wpf designer</int> [modified] Pin
vincentgr31-Oct-08 8:02
vincentgr31-Oct-08 8:02 
AnswerRe: List in wpf designer Pin
Pedram Behroozi31-Oct-08 8:16
Pedram Behroozi31-Oct-08 8:16 

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.