Home > Software engineering >  [big job for help!!] Want to use VB to simulate a small drawing board, how to paint on the picturebo
[big job for help!!] Want to use VB to simulate a small drawing board, how to paint on the picturebo

Time:10-02

I found the original code is such, is in the form of, can run
I want to change to draw on the picturebox is line did not follow the mouse to do

This is the original code in the form:
 Private Sub Form1_MouseDown (ByVal sender As Object, ByVal e the As System. Windows, Forms the MouseEventArgs) Handles Me. MouseDown 'when the left mouse button is pressed, the DrawState is set to True, said put pen to paper began to draw lines 
Dim g As Graphics=Me. CreateGraphics If e.B utton=Windows. Forms. MouseButtons. Left Then DrawState=True 'set the drawing state
Pre=e.X 'pre, and PreY to save the starting point of the line,
PreY=e.Y
End the If
End Sub
Private Sub Form1_MouseMove (ByVal sender As Object, ByVal e the As System. Windows, Forms the MouseEventArgs) Handles Me. MouseMove 'when the mouse moves, if in a state of line drawing, in the (pre, PreY) and draw a straight line between (X, Y)
Dim g As Graphics=Me. CreateGraphics
If DrawState=True Then
G.D rawLine (eP, pre, PreY, e.X, e.Y)
Pre=e.X
PreY=e.Y
End the If
End Sub
Private Sub Form1_MouseUp (ByVal sender As Object, ByVal e the As System. Windows, Forms the MouseEventArgs) Handles Me. MouseUp 'lift its state of line drawing when release the left mouse button,
If e.B utton.=Windows Forms. MouseButtons. Left Then
DrawState=False
End the If
End Sub
Private Sub Form1_Resize (ByVal sender As Object, ByVal e the As System. EventArgs) Handles Me. Resize
G=Me. CreateGraphics
End Sub
The End of the Class


I change after: (or moving the mouse will have reaction on the form, and lines don't follow the mouse)
 Public Class Form1 
Dim DrawState As Boolean
Dim pre, As Single
Dim PreY As Single
Dim eP As New Pen (Color Black, 3) 'Black brush structure, and to assign it to the object variable eP

Dim g As Graphics

'field on your form to construct a piece of canvas, and assign it to the object variable g
Private Sub Form1_Load (sender As Object, As EventArgs e) Handles MyBase. Load
'will DrawState initialized to False, said pen
DrawState=False


End Sub


Private Sub Form1_MouseDown (sender As Object, e As MouseEventArgs) Handles MyBase. The MouseDown
'when the left mouse button is pressed, the DrawState is set to True, said put pen to paper began to draw lines
G=PictureBox3. CreateGraphics ()
If e.B utton.=Windows Forms. MouseButtons. Left Then
DrawState=True 'set the drawing state
Pre=MousePosition. X
'pre, and PreY to save the starting point of the line,
PreY=MousePosition. Y
End the If
End Sub

Private Sub Form1_MouseMove (sender As Object, e As MouseEventArgs) Handles MyBase, MouseMove
'when the mouse moves, if in a state of line drawing, in the (pre, PreY) and draw a straight line between (X, Y)
G=PictureBox3. CreateGraphics ()
If DrawState=True Then
G.D rawLine (eP, pre, PreY, MousePosition. X, MousePosition. Y)
Pre=MousePosition. X
PreY=MousePosition. Y
End the If
End Sub

Private Sub Form1_MouseUp (sender As Object, e As MouseEventArgs) Handles MyBase, MouseUp
'when release the left mouse button, the lift line drawing state
If e.B utton.=Windows Forms. MouseButtons. Left Then

End the If
DrawState=False
End Sub

Private Sub Form1_Resize (sender As Object, As EventArgs e) Handles MyBase. Resize
G=PictureBox3. CreateGraphics ()
End Sub

Private Sub GroupBox1_Enter (sender As Object, As EventArgs e) Handles GroupBox1. Enter

End Sub

CodePudding user response:

Since switching to PictureBox operation, then the MouseDown, MouseMove, MouseUp will convert PictureBox event!

CodePudding user response:

But he says there is no mousebutton picturebox what parameters...

CodePudding user response:

Who said that? Go out turn right a mental hospital,
  • Related