Freehand Draw

xiaoxiao2021-03-06  15

Public class form1 inherits system.windows.Forms.form

#Region "Windows Form Designer Generated Code"

Public Sub new () mybase.new ()

'This call is required for the Windows Form Designer. InitializeComponent ()

'Add any initialization after INITIALIZECOMPONENT ()

End Sub

'Form rewriting Dispose to clean up the list of components. Protected overloads overrides sub dispose (byval disposing as boolean) ing disponation kiln (Components Is Nothing) Then components.dispose () end if endiffs) End sub

'Windows Form Designer Supply Private Components as System.comPonentModel.icontainer

'Note: The following procedure is necessary to use the Windows Form Designer to modify this process using the Windows Form Designer. 'Don't modify it using the code editor.

Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox Friend WithEvents Label1 As System.Windows.Forms.Label Private Sub InitializeComponent () Me.PictureBox1 = New System.Windows.Forms.PictureBox Me. label1 = New System.Windows.Forms.Label Me.SuspendLayout () '' PictureBox1 'Me.PictureBox1.BackColor = System.Drawing.Color.FromArgb (CType (192, Byte), CType (192, Byte), CType (255 , Byte)) Me.PictureBox1.Location = New System.Drawing.Point (24, 64) Me.PictureBox1.Name = "PictureBox1" Me.PictureBox1.Size = New System.Drawing.Size (440, 232) Me.PictureBox1 .TabIndex = 0 Me.PictureBox1.TabStop = False '' Label1 'Me.Label1.Font = New System.Drawing.Font ( "Arial", 12.0 !, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point , Ctype (134, byte) me.label1.location = new system.drawing.point (40, 24) me.label1.name = "Label1" me.label1.size = new system.drawing.size (416, 32) me.label1.tabindex = 1 me.label1.text = "free hand draw by WGSCD QQ: 153964481" 'Form1' ME. AutoScaleBasesize = new system.drawing.size (6, 14) me.umbcolor = system.drawing.color.Fromargb (ctype (255, byte), ctype (224, byte), ctype (192, byte) me.clientsize = New system.drawing.size (496, 334) me.controls.add (me.label1) me.controls.add (me.picturebox1) me.name = "form1" me.text = "form1" me.ResumeLayout (false) )

End Sub # end region

Dim mousePath As New System.Drawing.Drawing2D.GraphicsPath 'declare a new Graphic path to follow the mouse movement Dim myAlpha As Integer = 100' declare a Alpha variable Dim myUserColor As New Color 'this is a color the user selects Dim myPenWidth As Single = 5 'set Pen Width Variable

Private Sub PictureBox1_mousedown (Byval e as mouseeventargs) Handles PictureBox1.mousedown

If E.BUTTON = MouseButtons.Left the 'Draw A Filled Circle IF LEFT MOUSE IS DOWN

Mousepath.startfigure () 'The l mouse is down sowe need to start a new line in mousepath

END IF

End Sub

Private Sub PictureBox1_mousemove (Byval e as system.windows.forms.mouseeventargs) Handles PictureBox1.mousemove

If E.BUTTON = MouseButtons.Left the 'Draw A Filled Circle IF LEFT MOUSE IS DOWN

Try MousePath.Addline (E.X, E.Y, E.X, E.Y) 'Add Mouse Coordiantes to MousePath

Catch Msgbox ("No Way, Hose!") End Try

END IF

Picturebox1.invalidate () 'Repaint The Picturebox Using The PictureBox1 Paint Event

End Sub

Private sub picturebox1_paint (Byval e as system.windows.forms.painteventargs) Handles PictureBox1.paint

Try

MyuserColor = (System.drawing.color.black) myalpha = 100

DIM Currentpen = New Pen (Color.Fromargb (MyAlpha, MyuserColor), MypenWidth '' set up the pen

E.Graphics.drawpath (currentpen, mousepath) 'DRAW the PATH! :)

Catch 'msgbox ("not happy!") End Try

End Sub

Private Sub Form1_Load (Byval E AS System.Object, Byval E AS System.Eventargs) Handles MyBase.Load

转载请注明原文地址:https://www.9cbs.com/read-45793.html

New Post(0)