#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    64
    Rep Power
    11

    Create onClick event


    I created an own component which contains a button. How can I create an onClick event for this button? This onClick should be visible in the property-window!

    I found this code but I do not know what to do next?

    Code:
    __property CodeEventReferenceExpression* get_Event();
    
    __property void set_Event(CodeEventReferenceExpression*);
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Location
    Bavaria, Germany
    Posts
    140
    Rep Power
    12
    Assuming you're coding a Windows Application (not a ASP.Net Web UserControl)...

    Just define a public event and a custom delegate (if you want to)...that's it :-)

    Code:
    public class UserControl1 : System.Windows.Forms.UserControl {
      
      // ...
      
      public event EventHandler OnClick;
      
      // ...
      
      public void SomeFuncWhichFiresClickEvent() {  
        // ...
        
        // fire event
        if (OnClick != null)
          OnClick(this, new EventArgs());    
      }
      
      // ...
     
    }
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    64
    Rep Power
    11
    I tried your example but got those errors:

    c2146: missing ';' before identifier 'EventHandler'
    c2501: 'GStatusBar::GStatusBarControl::event' : missing storage-class or type specifiers

    What´s wrong?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Location
    Bavaria, Germany
    Posts
    140
    Rep Power
    12
    Hmm, your error message looks like you're coding in C++? Perhaps some of the moderators should append to the "READ: How To Post" a short message that new posts in this specific board should add Language (c++, c# or VB) and what section, so its easier to track down what is ment (since the topic of this board is very wide-ranged...)

    Try this one:

    Code:
    __gc class YourClass {
    
    public:
       __event ClickEventHandler* OnClick;  // declare the event 
    
       void FireEvents() {
          OnClick(0, 1);
       }
    
    };
    The code you saw is what the compiler generates out of the above statements, see http://msdn.microsoft.com/library/de...onsSpec_10.asp.

    That should do the trick

IMN logo majestic logo threadwatch logo seochat tools logo