|D Shen wrote:
I am not sure if I understand what you mean by
It's the beauty of inheritance
OK. Lets see how/why I say that
1. What we want is a button that we can programatically fire events. It makes sense to add this functionality to the Button class. So we make one:
public class ButtonEx():System.Windows.Forms.Button
public void CallButtonclick()
2. We replace our existing Button in the in the form with our new ButtonEx.
private System.Windows.Forms.Button button1;
private ButtonEx button1;
And in the windows forms designer region, change :
button1 = new System.Windows.Forms.Button();
button1 = new ButtonEx();
Be sure to save before viewing in the designer(in fact close it beforehand, it does more harm than good ).
3. Finally we just call our new ButtonEx's CallButtonClick methods as follows:
NOTE: If you'll be calling this method from thread u will need to invoke it. I'm not 100% sure, but it would look something like this:
button1.Invoke( new MethodInvoker(button1.CallButtonClick));
Hope this adds some insight
Give them a chance! Do it for the kittens, dear God, the kittens!