自定义控件重载ProcessDialogKey

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);
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值