C#做一个小游戏,想弄那种如果鼠标碰到了一个移动中的picturebox,程序就结束的那种,求代码。。

2025-02-25 11:12:03
推荐回答(4个)
回答1:

通过MouseEnter事件判断即可。
为了更人性化,你可以设置下图片的安全区域。

定义图片类型。
public enum TargetType
{
General = 0, // 普通图片,
Bomb = 1, //移动炸弹
Point =2 //加分
}
自定义类,添加以下属性,类可以从PictureBox继承。

private TargetType m_TargetType =TargetType.General;
public TargetType TargetType
{
get{ return m_TargetType;}
set{ m_TargetType =value;}
}

MouseEnter事件中,判断下图片类型
如果是Bomb炸弹,Show Game Over

回答2:

根据屏幕坐标,picturebox的坐标和鼠标的坐标,来判断是不是picturebox和鼠标重叠在一起

回答3:

picturebox控件的事件列表里有这样一个事件!

当鼠标进入控件可视范围内时发生!名字叫MouseEnter

回答4:

picturebox+=mousemove(s,e)
{
//游戏结束
};