|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
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());
}
// ...
}
|
|
#3
|
|||
|
|||
|
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? |
|
#4
|
|||
|
|||
|
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/d...ionsSpec_10.asp. That should do the trick ![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > .Net Development > Create onClick event |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|