Help - Graphics to Image
If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
2 posts
Page 1 of 1
Hello i am using this simple code to paint on Picturebox1.creategraphics
Code: Select all
And i wanted to know how to convert this so that it is on picturebox1.imagePrivate Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
'If the left mouse button is down the set IsThePenDown to TRUE
If e.Button = Windows.Forms.MouseButtons.Left Then
IsThePenDown = True
'Set the Point to start drawing from.>>
MouseDownPoint = New Point(e.X, e.Y)
End If
End Sub
Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
'A STATIC variable holds or remebers the previous value.>>
Static LastPoint As New Point
If IsThePenDown = True Then
'Draw a line from the LastPoint.>>
PictureBox1.CreateGraphics.DrawLine(MyPen, LastPoint.X, LastPoint.Y, e.X, e.Y)
End If
'Set the LastPoint to the previous point.>>
LastPoint = New Point(e.X, e.Y)
End Sub
Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
'Set to FALSE on the MouseUp event.>>
IsThePenDown = False
End Sub
You would need to add this code:
Code: Select all
Then you can alter the PictureBox1_MouseMove event:
Dim gfx As Graphics
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
PictureBox1.Image = New Bitmap(PictureBox1.Width, PictureBox1.Height)
gfx = Graphics.FromImage(PictureBox1.Image)
End Sub
Code: Select all
Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
'A STATIC variable holds or remebers the previous value.>>
Static LastPoint As New Point
If IsThePenDown = True Then
'Draw a line from the LastPoint.>>
gfx.DrawLine(MyPen, LastPoint.X, LastPoint.Y, e.X, e.Y)
PictureBox1.Refresh()
End If
'Set the LastPoint to the previous point.>>
LastPoint = New Point(e.X, e.Y)
End Sub
2 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023