日期:2014-05-17 浏览次数:20773 次
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
tank mtk = new tank();
mtk.Image = Image.FromFile("black.png");
mtk.Location = new Point(100, 200);
mtk.SizeMode = PictureBoxSizeMode.AutoSize;
this.Controls.Add(mtk);
mtk.yourkeypress += new tank.mykprs(mtk_yourkeypress);
}
void mtk_yourkeypress(object sender,MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{ MessageBox.Show("haha", "haha"); }
}
public class tank : PictureBox
{
public delegate void mykprs(object sender, MouseEventArgs e);
public event mykprs yourkeypress;
}
}
public class tank : PictureBox
{
public delegate void mykprs(object sender, MouseEventArgs e);
public event mykprs yourkeypress;
protected override void OnMouseClick(MouseEventArgs e)
{
if (yourkeypress != null)
yourkeypress(this, e);
base.OnMouseClick(e);
}
}