دوست عزيز اين هم يه نمونه خيلي ساده واسه كاري كه شما ميخوايد انجام بديد
اميد وارم به كارتون بياد
Dim X, Y, _X, _Y AsInteger
Dim Clicks AsInteger = 0
PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text <> ""And TextBox2.Text <> ""Then
Dim Graphic As Graphics = MyBase.CreateGraphics
Graphic.FillRectangle(Brushes.SpringGreen, 50, 100, CInt(TextBox2.Text), CInt(TextBox1.Text))
Graphic.DrawRectangle(Pens.Black, 50, 100, CInt(TextBox2.Text), CInt(TextBox1.Text))
Graphic.Dispose()
EndIf
EndSub
PrivateSub Form1_MouseClick(ByVal sender AsObject, ByVal e As System.Windows.Forms.MouseEventArgs) HandlesMe.MouseClick
SelectCase Clicks
Case 0
X = e.X
Y = e.Y
Clicks = 1
Case 1
_X = e.X
_Y = e.Y
Clicks = 0
EndSelect
EndSub
PrivateSub Form1_MouseMove(ByVal sender AsObject, ByVal e As System.Windows.Forms.MouseEventArgs) HandlesMe.MouseMove
If Clicks = 1 Then
_X = e.X
_Y = e.Y
Line()
EndIf
EndSub
PrivateSub Line()
Dim Graphic As Graphics = MyBase.CreateGraphics
Graphic.Clear(Me.BackColor)
If TextBox1.Text <> ""And TextBox2.Text <> ""Then
Graphic.FillRectangle(Brushes.SpringGreen, 50, 100, CInt(TextBox2.Text), CInt(TextBox1.Text))
Graphic.DrawRectangle(Pens.Black, 50, 100, CInt(TextBox2.Text), CInt(TextBox1.Text))
EndIf
Graphic.DrawLine(Pens.Red, X, Y, _X, _Y)
Graphic.Dispose()
EndSub