Click here to Skip to main content
15,918,742 members
Home / Discussions / C#
   

C#

 
GeneralRe: Oval buttons and using transparency Pin
mav.northwind25-Jan-08 21:55
mav.northwind25-Jan-08 21:55 
QuestionCan I raise an event for a class rather than an object? Pin
Clive D. Pottinger25-Jan-08 7:42
Clive D. Pottinger25-Jan-08 7:42 
GeneralRe: Can I raise an event for a class rather than an object? Pin
Ed.Poore25-Jan-08 7:45
Ed.Poore25-Jan-08 7:45 
GeneralRe: Can I raise an event for a class rather than an object? Pin
Clive D. Pottinger25-Jan-08 10:19
Clive D. Pottinger25-Jan-08 10:19 
GeneralRe: Can I raise an event for a class rather than an object? Pin
Ed.Poore25-Jan-08 12:18
Ed.Poore25-Jan-08 12:18 
AnswerRe: Can I raise an event for a class rather than an object? Pin
BoneSoft25-Jan-08 8:16
BoneSoft25-Jan-08 8:16 
GeneralRe: Can I raise an event for a class rather than an object? Pin
Clive D. Pottinger25-Jan-08 10:50
Clive D. Pottinger25-Jan-08 10:50 
GeneralRe: Can I raise an event for a class rather than an object? Pin
BoneSoft25-Jan-08 12:12
BoneSoft25-Jan-08 12:12 
I apologize for the assumption, from your post I wasn't sure you were actually using events.

I don't think you'll need static events, unless that's what you want to do. If B has an event, when A creates those instances it should be able to hook the new B instance's events to a method of it's own. Also on creation of the B instances, you can set them up as subscribers to events that A has.

Is this the kind of thing you're talking about? Or did I completely misunderstand your question?
C#
class A {
    // A has an event to notify B instances with
    public event EventHandler OnA;
 
    public void Start() {
        B b1 = new B(1);
        // hook B event to my method
        b1.OnB += new EventHandler(CatchOnB);
        // hook B method to my event
        OnA += new EventHandler(b1.CatchOnA);
 
        B b2 = new B(2);
        b2.OnB += new EventHandler(CatchOnB);
        OnA += new EventHandler(b2.CatchOnA);
 
        b1.DoStuff();
        b2.DoStuff();
        if (OnA != null) {
            OnA(this, EventArgs.Empty);
        }
    }
 
    private void CatchOnB(object sender, EventArgs e) {
        Console.WriteLine("B{0} called me", ((B)sender).Id);
    }
}
 
class B {
    public event EventHandler OnB;

    public int Id;
 
    public B(int id) {
        this.Id = id;
    }
 
    public void CatchOnA(object sender, EventArgs e) {
        Console.WriteLine("A called B{0}", Id);
    }
 
    public void DoStuff() {
        if (OnB != null) {
            OnB(this, EventArgs.Empty);
        }
    }
}




Try code model generation tools at BoneSoft.com.

GeneralRe: Can I raise an event for a class rather than an object? Pin
Clive D. Pottinger1-Apr-08 11:13
Clive D. Pottinger1-Apr-08 11:13 
GeneralRe: Can I raise an event for a class rather than an object? Pin
BoneSoft1-Apr-08 13:06
BoneSoft1-Apr-08 13:06 
GeneralRe: Can I raise an event for a class rather than an object? Pin
Ennis Ray Lynch, Jr.25-Jan-08 8:20
Ennis Ray Lynch, Jr.25-Jan-08 8:20 
GeneralRe: Can I raise an event for a class rather than an object? Pin
led mike25-Jan-08 8:27
led mike25-Jan-08 8:27 
QuestionWhats the correct way to populate the DataSource in SubReports? [modified] Pin
DeepToot25-Jan-08 7:31
DeepToot25-Jan-08 7:31 
QuestionDeploy a web service Pin
usermans25-Jan-08 6:13
usermans25-Jan-08 6:13 
GeneralRe: Deploy a web service Pin
led mike25-Jan-08 6:48
led mike25-Jan-08 6:48 
Generalimage transparent Pin
netJP12L25-Jan-08 5:34
netJP12L25-Jan-08 5:34 
GeneralRe: image transparent Pin
Ennis Ray Lynch, Jr.25-Jan-08 6:25
Ennis Ray Lynch, Jr.25-Jan-08 6:25 
GeneralRe: image transparent Pin
netJP12L25-Jan-08 9:28
netJP12L25-Jan-08 9:28 
GeneralRe: image transparent Pin
Ennis Ray Lynch, Jr.25-Jan-08 9:33
Ennis Ray Lynch, Jr.25-Jan-08 9:33 
GeneralTaskbarNotifier in Client Server Application Pin
ALI BIN ABID25-Jan-08 4:04
ALI BIN ABID25-Jan-08 4:04 
GeneralRe: TaskbarNotifier in Client Server Application Pin
DaveyM6925-Jan-08 4:13
professionalDaveyM6925-Jan-08 4:13 
GeneralRe: TaskbarNotifier in Client Server Application Pin
ALI BIN ABID25-Jan-08 4:22
ALI BIN ABID25-Jan-08 4:22 
QuestionWhat is Dirty ? Pin
Nadia Monalisa25-Jan-08 4:01
Nadia Monalisa25-Jan-08 4:01 
AnswerRe: What is Dirty ? Pin
DaveyM6925-Jan-08 4:06
professionalDaveyM6925-Jan-08 4:06 
GeneralRe: What is Dirty ? Pin
Nadia Monalisa25-Jan-08 4:26
Nadia Monalisa25-Jan-08 4:26 

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.