Click here to Skip to main content
15,923,015 members
Home / Discussions / C#
   

C#

 
GeneralMaking button jump to anchor Pin
Anonymous14-May-03 6:13
Anonymous14-May-03 6:13 
Questionhow does serialization handle versions? Pin
dazinith14-May-03 4:59
dazinith14-May-03 4:59 
AnswerRe: how does serialization handle versions? Pin
James T. Johnson14-May-03 14:00
James T. Johnson14-May-03 14:00 
Generalchild form to maximize in work area in parent Pin
zuhx14-May-03 4:44
zuhx14-May-03 4:44 
Questioncan we make label transparent? Pin
Itanium14-May-03 3:29
Itanium14-May-03 3:29 
AnswerRe: can we make label transparent? Pin
KingTermite15-May-03 3:36
KingTermite15-May-03 3:36 
GeneralRaising an event Pin
Andy H14-May-03 2:03
Andy H14-May-03 2:03 
GeneralRe: Raising an event Pin
Richard Deeming14-May-03 5:19
mveRichard Deeming14-May-03 5:19 
You need to declare a protected virtual method called OnEventName in the base class, which raises the event. Derived classes can then call this method to raise the event, or override it to intercept the event.

Also, Event handler delegates should always take two arguments - an object and a class derived from EventArgs.

For example:
public abstract class MyBaseClass
{
    public delegate void BtEventHandler(object sender, EventArgs e);
    
    public event BtEventHandler RecordImported;
    
    protected virtual void OnRecordImported(EventArgs e)
    {
        if (null != RecordImported)
        {
            try
            {
                RecordImported(this, e);
            }
            catch
            {
                // Ignore any errors raised 
                // in event handlers
            }
        }
    }
}
 
public class MyDerivedClass : MyBaseClass
{
    public void ImportRecord()
    {
        // Raise the RecordImported event:
        OnRecordImported(EventArgs.Empty);
    }
    
    // If you need to intercept the event, it
    // is much more efficient to override the
    // method than to attach an event handler
    // to the event.
    protected override void OnRecordImported(EventArgs e)
    {
        Console.WriteLine("Intercepted the RecordImported event");
        base.OnRecordImported(e);
    }
}



"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
GeneralC# dll Pin
dhruvesh14-May-03 1:26
dhruvesh14-May-03 1:26 
GeneralAdding DataColumns becames slow Pin
A.Wegierski14-May-03 0:01
A.Wegierski14-May-03 0:01 
GeneralRe: Adding DataColumns becames slow Pin
A.Wegierski14-May-03 0:40
A.Wegierski14-May-03 0:40 
GeneralCombo Box Hell please help!!! Pin
Paul Griffin13-May-03 23:35
Paul Griffin13-May-03 23:35 
GeneralRegarding DllImport Pin
jtmtv1813-May-03 22:02
jtmtv1813-May-03 22:02 
GeneralRe: Regarding DllImport Pin
Jon Newman13-May-03 22:10
Jon Newman13-May-03 22:10 
GeneralQuestion about spider or web crawler Pin
benzite13-May-03 20:53
benzite13-May-03 20:53 
GeneralRe: Question about spider or web crawler Pin
Sarvesvara (BVKS) Dasa13-May-03 21:19
Sarvesvara (BVKS) Dasa13-May-03 21:19 
GeneralRe: Question about spider or web crawler Pin
benzite13-May-03 21:57
benzite13-May-03 21:57 
GeneralRe: Question about spider or web crawler Pin
leppie14-May-03 9:47
leppie14-May-03 9:47 
GeneralRe: Question about spider or web crawler Pin
benzite14-May-03 19:13
benzite14-May-03 19:13 
GeneralProblems with dll's in C# Pin
flyingv13-May-03 20:25
flyingv13-May-03 20:25 
GeneralRe: Problems with dll's in C# Pin
cdehelean13-May-03 21:32
cdehelean13-May-03 21:32 
GeneralRe: Problems with dll's in C# Pin
flyingv13-May-03 21:54
flyingv13-May-03 21:54 
QuestionDuplicate 'using' statements = inefficient ? Pin
nosmij13-May-03 20:09
nosmij13-May-03 20:09 
AnswerRe: Duplicate 'using' statements = inefficient ? Pin
Jon Newman13-May-03 22:06
Jon Newman13-May-03 22:06 
GeneralRe: Duplicate 'using' statements = inefficient ? Pin
nosmij13-May-03 23:04
nosmij13-May-03 23:04 

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.