public class CMyButton: Button
{
public delegate void Delegate_KeysEvent(object sender, EventArgs args);
public event Delegate_KeysEvent Key_Up;
public event Delegate_KeysEvent Key_Down;
public event Delegate_KeysEvent Key_Left;
public event Delegate_KeysEvent Key_Right;
protected override bool ProcessDialogKey(Keys keyData)
{
switch(keyData)
{
case Keys.Up:
if(Key_Up!=null)
{
Key_Up(this,new MyKeyEventArgs(“Up”));
}
break;
case Keys.Down:
if (Key_Down != null)
{
Key_Down(this, new MyKeyEventArgs(“Down”));
}
break;
case Keys.Left:
if (Key_Left != null)
{
Key_Left(this, new MyKeyEventArgs(“Left”));
}
break;
case Keys.Right:
if (Key_Right != null)
{
Key_Right(this, new MyKeyEventArgs(“Right”));
}
break;
}
return base.ProcessDialogKey(keyData);
}
}
public class MyKeyEventArgs:EventArgs
{
public string Label { get; set; }
public MyKeyEventArgs(string param_label)
{
Label = param_label;
}
}
///
Panel = new CMyButton();
Panel.BackColor = System.Drawing.Color.Transparent;
Panel.Size = new System.Drawing.Size((int)Width,(int)Height);
Panel.Location = new System.Drawing.Point((int)(Xscale*param_ownedMapWidth),(int)(Yscale*param_ownedMapHeight));
Panel.BackgroundImage = Properties.Resources.ok;
Panel.BackgroundImageLayout = ImageLayout.Stretch;
Panel.FlatStyle = FlatStyle.Flat;
Panel.FlatAppearance.BorderSize = 0;
owner.Controls.Add(Panel);
Panel.Parent = owner;
//
Panel.Key_Up += Panel_Key_Up;
Panel.Key_Down += Panel_Key_Down;
Panel.Key_Left += Panel_Key_Left;
Panel.Key_Right += Panel_Key_Right;
}
private void Panel_Key_Right(object sender, EventArgs args)
{
Point _point = Panel.Location;
Panel.Location = new Point(_point.X += 1, _point.Y);
}