开发者

Panel events won't work in c#

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.

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.

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.

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.

Anyone could help me with that?

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


Most likely the Move and Hover events go to the topmost control (the labels). Is any of your Panel showing?

You might be able to Capture the mouse in the MouseEnter event of the Panel.

boardPanel.Capture = true;

But this might interfere with the mouse-handling in the labels.

All in all, you'll probably find that getting this (UI) right is a lot harder than it looks. Consider a simpler act-on-click design. To start with.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜