I want to make a button that acts with the keyboard as with the mouse. I'm implementing it this way:
class FunctionButton : System.Windows.Forms.Button
{
public FunctionButton() : base() { }
protected override void OnGotFocus(EventArgs e)
{
OnMouseEnter(null);
base.OnGotFocus(e);
}
protected override void OnLostFocus(EventArgs e)
{
OnMouseLeave(null);
base.OnLostFocus(e);
}
protected override void OnMouseLeave(EventArgs e)
{
if (!Focused)
{
base.OnMouseLeave(e);
}
}
public void FunctionKeyPressed()
{
OnMouseDown(new MouseEventArgs(MouseButtons.Left,1,0,0,0));
PerformClick();
}
public void FunctionKeyReleased()
{
if (Focused)
{
OnMouseEnter(null);
}
else
{
base.OnMouseLeave(null);
}
}
}
I don't know how to get a valid click position for this button to generate de event
OnMouseDown(new MouseEventArgs(MouseButtons.Left,1,X,Y,0));
How can I do this? Is the better way to implement this kind of button?