Control Problem
-
I created a custom control derived from a panel in which I added flat buttons but how can I add action on the buttons dynamicly ??? I can't because the class is derived from a panel. Anybody can help me ?
You could expose your buttons via a property as a collection (of buttons). But then you are exposing everything about the buttons.
-
I created a custom control derived from a panel in which I added flat buttons but how can I add action on the buttons dynamicly ??? I can't because the class is derived from a panel. Anybody can help me ?
You can expose event properties on your control; like so...
public EventHandler ButtonA_Click
{
add
{
buttona.Click += new EventHandler(value);
}
remove
{
buttona.Click -= new EventHandler(value);
}
}You wind up with having to name the events something different, but you can control what events are available. HTH, James Simplicity Rules!
-
You could expose your buttons via a property as a collection (of buttons). But then you are exposing everything about the buttons.
Doh! Then again, there is nothing stopping you from accessing the built-in Controls collection of the Panel and attaching an event handler dynamically.
-
You can expose event properties on your control; like so...
public EventHandler ButtonA_Click
{
add
{
buttona.Click += new EventHandler(value);
}
remove
{
buttona.Click -= new EventHandler(value);
}
}You wind up with having to name the events something different, but you can control what events are available. HTH, James Simplicity Rules!
The problem is that I create only one instance of a button and Each I wrote tb.AddItem("Test",Color.Black,Color.White,0); (that's an example) the control add a button itself to the parent control which is a panel. so how can I handle all the buttons actions when I have only one Button Instance ?? can I make a function like ItemClick(int index,EventHandler action) ?? if yes can u plz give me some code because I try to use this with a switch statement and I got an error : "a value constant is expected" Thanks
-
The problem is that I create only one instance of a button and Each I wrote tb.AddItem("Test",Color.Black,Color.White,0); (that's an example) the control add a button itself to the parent control which is a panel. so how can I handle all the buttons actions when I have only one Button Instance ?? can I make a function like ItemClick(int index,EventHandler action) ?? if yes can u plz give me some code because I try to use this with a switch statement and I got an error : "a value constant is expected" Thanks
I'm having a hard time making out what you are trying to do so let me know if what I suggest answers a different problem. What I think you're having a problem with is you only have one real button, but you have multiple click events that need to fire. Using the event handler I described above works fine; it properly handles firing of chained events (multiple methods to run when one event fires). I'm unsure what your ItemClick function is meant to do though; can you describe in words or psuedo-code what it would do? James Simplicity Rules!
-
I'm having a hard time making out what you are trying to do so let me know if what I suggest answers a different problem. What I think you're having a problem with is you only have one real button, but you have multiple click events that need to fire. Using the event handler I described above works fine; it properly handles firing of chained events (multiple methods to run when one event fires). I'm unsure what your ItemClick function is meant to do though; can you describe in words or psuedo-code what it would do? James Simplicity Rules!