Here's My Solution
class YoButton : System.Windows.Forms.Button
{
public event System.EventHandler Selection;
public YoButton()
{
this.KeyUp +=new KeyEventHandler(keyUp);
this.MouseUp += new MouseEventHandler(mouseUp);
}
protected void mouseUp(object obj, MouseEventArgs mev){
if( mev.Button == MouseButtons.Left )
raiseSelected();
}
protected void keyUp(object obj, KeyEventArgs kev){
if( kev.KeyCode == Keys.Enter || kev.KeyCode == Keys.Space )
raiseSelected();
}
protected void raiseSelected(){
if( this.Selection != null )
this.Selection(this, new System.EventArgs());
}
}
And Then...
InitComponent()
{
this.button1.Selection += new EventHandler(Button1Click);
this.listBox1.KeyPress += new KeyPressEventHandler(this.ListBoxKeyPress);
this.listBox1.KeyUp += new KeyEventHandler(this.ListBoxKeyUp);
this.listBox1.KeyDown += new KeyEventHandler(this.ListBoxKeyDown);
this.listBox1.GotFocus += new System.EventHandler(listGotFocus);
}
void Button1Click(Object sender, EventArgs e)
{
Console.WriteLine("Btn Clicked");
this.listbox1.Focus();
}
void listGotFocus(object sen, EventArgs e)
{
Console.WriteLine("Listbox got Focus");
}
void ListBoxKeyDown(Object sender, KeyEventArgs kev)
{
Console.WriteLine("List KeyDown");
}
void ListBoxKeyUp(Object sender, KeyEventArgs kev)
{
Console.WriteLine("List KeyUp");
}
void ListBoxKeyPress(Object sender, KeyPressEventArgs kev)
{
Console.WriteLine("List Key Pressed");
}
Now if we handle button1.Click Event Then Output is
Btn Clicked
Listbox got Focus
List KeyUp
If We handle button1.Selection (Custom Event) Then Output is
Btn Clicked
Listbox got Focus
Which is what I want
Thanks Everybody...
Enter your message below
Sign in or Join us (it's free).