面板事件在 c# 中不起作用 [英] Panel events won't work in c#

查看:38
本文介绍了面板事件在 c# 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好我在大学项目中遇到了一些问题.我正在用 C# 为我大学的 C# 课程中的一个项目构建一个4 in a row"游戏.

Hi all I'm struggling with some problem in a project from college. I'm building a "4 in a row" game in c# for a project in my c# course at my college.

我创建了一个名为 GameForm 的表单,并在其中添加了一个名为 panelBoardGame 的面板.在那个 panelBoardGame 中,我添加了一组可点击的标签(以执行移动),我还添加了一个标签矩阵,以表示 Board 本身.

I have created a Form named GameForm and inside it I added a Panel named panelBoardGame. to that panelBoardGame I added an array of labels to be clickable (to execute a move) and i added a matrix of labels too , to represent the Board itself.

现在,我的任务是只要鼠标在面板区域内,某个玩家的 CoinImage 就会随着光标移动,只要它在面板区域内.当鼠标在区域外时,CoinImage 不会显示.

Now, my mission is whenever the mouse is inside the Panel area, the CoinImage of a certain player is moving along with the Cursor as long it is inside the panel area. when the mouse is outside the area, the CoinImage wont show.

为此,我尝试触发 panelBoardGame 的 onMouseEnter,OnMouseLeave 事件,但不知何故它们甚至不会被执行.每当我的鼠标在 panelBoardGame 区域内时,panelBoardGame_MouseMove(......) 函数内的代码就不会被执行.

To do so I tried triggering the onMouseEnter,OnMouseLeave events of the panelBoardGame, but somehow they wont even get executed. Whenever my mouse is inside the panelBoardGame area the code inside panelBoardGame_MouseMove(......) function doesn't get executed.

有人可以帮我吗?

因为我是新来的我不能发图片,但我把图片上传到这里表格图片

Since im new here i cant post images, but ive uploaded the image to here Image of the Form

这是表单的图像,里面有一个黑色边框,周围是面板,在面板里面我添加了标签

Here is the image of the Form, inside it with a border in black around it is the panel and inside the panel i added labels

推荐答案

让我猜猜,您的标签完全覆盖了面板区域.在 Windows 中,只有顶部控件接收鼠标事件.因此,当鼠标悬停在您的标签之一上时,鼠标事件会转到标签,而不是包含标签的面板.所以在你的标签上设置一个 MouseMove 事件处理程序,你会看到它执行.

Let me guess, your labels completely cover the the area of the panel. In Windows only the top control receives mouse events. So when the mouse is over one of your labels the mouse events go to the label, not to the panel that contains the label. So set a MouseMove event handler on your labels and you'll see that execute.

这篇关于面板事件在 c# 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆