标签上包含C#键 [英] C# bonds contains on a label
问题描述
这是mt代码
beatdetector = picurebox
this is mt code
beatdetector= picurebox
foreach (Control pControl in panel1.Controls)
{
Label pLabel=pControl as Label;
if (null != pLabel)
{
if (BeatDetector.Bounds.Contains(pLabel))
{
msgbox.show("it touched!!!");
}
}
}
这是我的2个错误
Error 1 The best overloaded method match for ''System.Drawing.Rectangle.Contains(System.Drawing.Rectangle)'' has some invalid arguments Z:\ll Studio\ll Studio\Form1.cs 193 29 ll Studio
Error 2 Argument 1: cannot convert from ''System.Windows.Forms.Label'' to ''System.Drawing.Rectangle'' Z:\ll Studio\ll Studio\Form1.cs 193 58 ll Studio
我知道它不是矩形或其他任何形状,但是我想知道这是否可能吗?
当他们触摸消息框时,便会显示
this is my 2 errors
Error 1 The best overloaded method match for ''System.Drawing.Rectangle.Contains(System.Drawing.Rectangle)'' has some invalid arguments Z:\ll Studio\ll Studio\Form1.cs 193 29 ll Studio
Error 2 Argument 1: cannot convert from ''System.Windows.Forms.Label'' to ''System.Drawing.Rectangle'' Z:\ll Studio\ll Studio\Form1.cs 193 58 ll Studio
I know its not a rectangle or whatever, but I was wondering if this is possible?
when they touch the message box is ment to show up
推荐答案
尝试:
if (BeatDetector.Bounds.Contains(new Rectangle(pLabel.Location, pLabel.Size)))
但是,您可能要改为检查四个角点中的每一个-Rectangle.Contains只会找到 整个 的对象在矩形内.如果您使用标签的边界矩形进行检查,则它将仅检测标签何时完全在BeatDetector内.您可以使用Rectangle.Contains(Point)或Rectangle.Contains(int,int)
However, you may want to check each of the four corner Points instead - Rectangle.Contains will only find objects which are entirely within the rectangle. If you check using the bounding rectangle for the label, then it will only detect when the label is entirely within the BeatDetector. You can use Rectangle.Contains(Point) or Rectangle.Contains(int, int)
这篇关于标签上包含C#键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!