如果光标与标签相交,如何使用if语句?(How to do an if statement for if a cursor intersects with a label?)

编程入门 行业动态 更新时间:2024-10-27 04:25:38
如果光标与标签相交,如何使用if语句?(How to do an if statement for if a cursor intersects with a label?)

我正在制作一个使用鼠标导航的迷宫游戏。

我已将标签放在面板上并使用面板离开事件,以便将光标重置回到开头。

但是有一个标签,它不应该重置,所以我想对这个标签做一个例外。 它的位置是300.400 ,它的大小是1,10 。

我打算在光标相交但没有像这样的特征的情况下制作一个if语句

Cursor.IntersectsWith()

那我怎么能这样做呢? 我也试着这样做

if cursor.position.x == 300

还有y东西,但事实证明x和y的位置与标签的位置无关? 如果光标与标签相交(或在标签上),我不知道如何做if语句。 请帮忙!

我知道我没有现成的代码,但问题非常明确!

I'm making a maze game that is navigated using a mouse.

I have put labels onto a panel and use the panel leave event in order to reset the cursor back to the beginning.

There is this one label though, that it should not be resetting at, and so I'd like to make an exception for this one label. It's location is 300.400 and it's size is 1,10.

I'm planning on making an if statement for if the cursor intersects but there is no feature like

Cursor.IntersectsWith()

so how would I be able to do this? I also tried to do

if cursor.position.x == 300

and something for y as well, but it turns out the position of x and y has nothing to do with the location of the label? I'm not sure how to do an if statement if the cursor is intersecting (or on) the label. Please help!

I'm aware I don't have code readily available, but the question is pretty clear!

最满意答案

要解决您的问题,有一个名为Label Name的属性。 我假设你正在使用WinForms,因为你没有提到框架。 不使用Loacation作为标识符,而是使用Label Name属性进行异常。 在PanelLeave事件处理程序中添加此代码: -

foreach(Label labels in LabelList) { if(labels.Name!="exception-label-name-here") Reset() ; // function to reset the cursor position. // LabelList is a list containin all the `Label`(s) in your panel. }

当您将Label添加到Panel时,此时将Label添加到我已命名为LabelList的通用列表中。

private void MouseEnter(object sender, EventArgs e ) { Label tmplbl = sender as Label ; if(tmplbl.Name == "some-name-here.") // do something else if(tmplbl.Name == "some other name") // do something else. // in this way construct a if-else ladder. }

To solve your question, there is a property called as Name for Label(s). I am assuming that you are using WinForms as you have mentioned nothing about the framework. Instead of using Loacation as an identifier, use Name property of Label to make an exception. Add this code inside the PanelLeave event handler:-

foreach(Label labels in LabelList) { if(labels.Name!="exception-label-name-here") Reset() ; // function to reset the cursor position. // LabelList is a list containin all the `Label`(s) in your panel. }

When you are adding Label(s) to your Panel, at that time add the Label(s) to a generic list which I have named as LabelList.

private void MouseEnter(object sender, EventArgs e ) { Label tmplbl = sender as Label ; if(tmplbl.Name == "some-name-here.") // do something else if(tmplbl.Name == "some other name") // do something else. // in this way construct a if-else ladder. }

更多推荐

cursor,标签,I'm,label,电脑培训,计算机培训,IT培训"/> <meta name="desc

本文发布于:2023-08-05 16:11:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1433936.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:光标   如何使用   语句   标签   label

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!