You're using the Forms events. If you want to interact with child controls
of the form you'll have to subscribe to their events individually.
--
Bob Powell [MVP]
Visual C#, System.Drawing
Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
[quoted text, click to view] "cmac89" <gg@bradan-aquasurveys.co.uk> wrote in message
news:1118751138.523965.54460@o13g2000cwo.googlegroups.com...
> I'm using the following code to draw a rectangle on a form and then
> move it to a new position by clicking the mouse. I would now like to
> do the same thing but within a picturebox. I've added the picturebox
> but the rectangle stops at the edge of the picturebox.
> I can't figure out how to change this code to confine the moving
> rectangle to within the picturebox
>
> Any help would be brilliant.
>
> Craig.
>
> -------------------------------------------
> Dim Rectangle1 As Rectangle = New System.Drawing.Rectangle(20, 100, 15,
> 15)
>
> Private Sub Form1_Paint(ByVal sender As Object, ByVal e As
> System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
> e.Graphics.FillRectangle(Drawing.Brushes.Black, Me.Rectangle1)
> End Sub
>
> Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As
> System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
> Me.Invalidate(Me.Rectangle1)
> Me.Rectangle1.X = e.X
> Me.Rectangle1.Y = e.Y
> Me.Invalidate(Me.Rectangle1)
> End Sub
> -------------------------------------------
>