Class and Picturebox

mmulibra

New member
Joined
Jan 12, 2005
Messages
2
Programming Experience
Beginner
Hi,

I have a class X and I would like create an instance of class X from Form1 according to the mousebutton click and location of the click
VB.NET:
Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
            Dim i As Integer
            Dim Xpos, YPos As Single
            Xpos = e.X
            YPos = e.Y
            If MouseButtons.Left Then
                i = i + 1
                X.node(Xpos, YPos)
   End If
        End Sub
From my class X, I would like create a circle in PictureBox1 in Form1:
VB.NET:
Public Class X
        Dim X, Y As Single
        Public Property node() As Single
            Get
     PictureBox1.Circle(Xpos, Ypos)
            End Get
            Set(ByVal Value As Single)
     X = Value
     Y = Value
            End Set
        End Property
I know this is not a correct way as I got some errors. Please give me some guidances.
 

srossitto

New member
Joined
Dec 27, 2009
Messages
1
Programming Experience
10+
I dont know why you want to use a separate Class to edit a locally instantied control. If you want to do that you should instantiate the class or make it shared and anyway you need to pass it a reference to the image.
I think that the correct way is this, in the same class of the control.

'*** CODE ***

Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
If MouseButtons.Left Then
DrawCircle(e.X, e.Y,10)
End If
End Sub

Sub DrawCircle(X,Y,R)
dim g as Graphics= Graphics.FromImage(PictureBox1.Image)
g.DrawCircle(Pens.Black,X,Y,R)
g.Save()
g.Dispose()
End Sub
 
Top Bottom