Click here to Skip to main content
15,914,013 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
this is mt code
beatdetector= picurebox

C#
foreach (Control pControl in panel1.Controls)
            {
              Label pLabel=pControl as Label;
              if (null != pLabel)
              {
if (BeatDetector.Bounds.Contains(pLabel))
                     {
                         msgbox.show("it touched!!!");
                     }

              }

             }


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
Posted

1 solution

Try:
C#
if (BeatDetector.Bounds.Contains(new Rectangle(pLabel.Location, pLabel.Size)))
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)
 
Share this answer
 
Comments
[no name] 7-Jun-12 21:04pm    
I found the answer just after I posted it then I lost internet, but I did already find the answer and it was, if (BeatDetector.Bounds.Contains(pLabel.bounds){} ,but that did not work, it was not detected, I'm yet to try your method, and ty btw
OriginalGriff 8-Jun-12 3:28am    
Welcome - and it didn't work because the Contains only reports true if the rectangle is fully contained.
[no name] 13-Jun-12 6:28am    
I tried your code, it did not work, nothing happens
OriginalGriff 13-Jun-12 6:35am    
What does or doesn't happen?
[no name] 13-Jun-12 6:43am    
when the beatdetor touches the control nothing happens

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900