Results 1 to 7 of 7

Thread: a question about events

  1. #1

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    a question about events

    I have this code
    PHP Code:
            internal event EBLinkClickedHandler onLinkClicked
            
    {
                
    add
                
    {
                    
    this.myLinkLabel.LinkClicked += new LinkLabelLinkClickedEventHandler (linkLabel_LinkClicked);
                }
                
    remove
                
    {
                    
    this.myLinkLabel.LinkClicked -= new LinkLabelLinkClickedEventHandler (linkLabel_LinkClicked);
                }
            } 
    it's basially an event property, or whatever it's called. The problem is that it won't let me fire the event by calling onLinkClicked()... is there any way to declare my event the way I just did above and still be able to fire it? when I try onLinkClicked() I get this error The event 'ControlsEx.ExplorerBarControl.EBLinkItem.onLinkClicked' can only appear on the left hand side of += or -=

    I can fire it if I dont declare the event as a property, but I kinda want to declare it that way
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  2. #2

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    nevermind I'm dumb
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  3. #3
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    Hmm? What are taht "add" and "remove" things inside of the event? I didn't know about it! Tell me what do they do and how do they work
    \m/\m/

  4. #4

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    hehe I dont quite know myself... I dont really "know" C#, I just opened up VS one day and started messing in C# and that's how I work

    in some situations I figure out that doing the events that way works a lot better for me. Add is when the user adds the event handler, and remove is called when you're removing it I guess

    I guess this could be one case where it can make it easier for you. But I dont really know what the real purpose of it is... maybe someone with a better C# knowledge can correct me if I'm wrong. But take a look at this example... may make more sense:
    PHP Code:
    private void Form1_Load(object senderSystem.EventArgs e)
            {
                
    this.WindowsDied += new EventHandler(Form1_WindowsDied);
            }

            private 
    void Form1_WindowsDied (object senderEventArgs e)
            {
                
    MessageBox.Show ("Your windows has passed away. Thank you");
            }

            public 
    event EventHandler WindowsDied
            
    {
                
    add
                
    {
                    
    this.Click += value;
                    
    this.Closed += value;
                    
    this.button1.Click += value;
                }
                
    remove
                
    {
                    
    this.Click -= value;
                    
    this.Closed -= value;
                    
    this.button1.Click -= value;
                }
            } 

    now if you click on button1, or the form, or if you close the form you get that message...

    btw does anyone know what exacly the purpose of the "event" keyword is? because it works without it also
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  5. #5

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    umm and regarding the first post, if you really want to be able to raise the event manually you gotto declare another variable:
    PHP Code:
    private EventHandler windowsDied;
            public 
    event EventHandler WindowsDied
            
    {
                
    add
                
    {
                    
    this.Click += value;
                    
    this.Closed += value;
                    
    this.button1.Click += value;
                    
    this.WindowsDied += value;
                }
                
    remove
                
    {
                    
    this.Click -= value;
                    
    this.Closed -= value;
                    
    this.button1.Click -= value;
                    
    this.WindowsDied -= value;
                }
            } 
    seems like stupid, I dont know if anyone does this
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  6. #6
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    That's weird . Add and Remove aren't keywords in C# , I believe . Some gurus use like these secrets by they don't explain what they're doing ...

  7. #7

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    haha lol
    hmm seems like this one is top secret I just accidentally figure it out...

    I guess the reason people havent seen it much is probably that it doesnt have much use anyways
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width