"Boki" <bo******@ms21. hinet.net> wrote
I think you all knew my problem.
I don't know how to draw line @@ in VB.NET (2005 beta) , very sad.
Coudl you please help me?
Here is a simple scribble demo. Paste the code below into a new
form, under the Designer code (section). I've used white to draw
the lines on the form. But, if you want that picture to stay after
resizing, or after minimizing (ect.) then you need to keep a bitmap
in memory to redraw the image. I've used black to draw to that
so you can see when that takes effect....
Have fun!
LFS
Private Page As Bitmap
Private Mouse As Point
Private Drawing As Boolean
Private PageGrx As Graphics
Private FormGrx As Graphics
Private BlackInk As Pen = New Pen(Color.Black , 2)
Private WhiteInk As Pen = New Pen(Color.White , 2)
Private MyPen As Pen
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
Page = New Bitmap(Me.Clien tSize.Width, Me.ClientSize.H eight)
ResetGraphics()
End Sub
Private Sub ResetGraphics()
If Not PageGrx Is Nothing Then PageGrx.Dispose ()
PageGrx = Graphics.FromIm age(Page)
PageGrx.Smoothi ngMode = Drawing2D.Smoot hingMode.AntiAl ias
If Not FormGrx Is Nothing Then FormGrx.Dispose ()
FormGrx = Me.CreateGraphi cs
FormGrx.Smoothi ngMode = Drawing2D.Smoot hingMode.AntiAl ias
End Sub
Private Sub Form1_SizeChang ed(ByVal sender As Object, ByVal e As System.EventArg s) Handles MyBase.SizeChan ged
' Bail if minimized / downsizing
If Me.WindowState = FormWindowState .Minimized Then Exit Sub
If (Me.Width * Me.Height) < (Page.Width * Page.Height) Then Exit Sub
' Copy old image to new
Dim tmp As Bitmap = New Bitmap(Me.Clien tSize.Width, Me.ClientSize.H eight)
Dim grx As Graphics = Graphics.FromIm age(tmp)
grx.DrawImageUn scaled(Page, 0, 0)
grx.Dispose()
Page.Dispose()
' Start using new image
Page = tmp
ResetGraphics()
End Sub
Private Sub Form1_Paint(ByV al sender As Object, ByVal e As System.Windows. Forms.PaintEven tArgs) Handles MyBase.Paint
If Not FormGrx Is Nothing Then
FormGrx.DrawIma geUnscaled(Page , 0, 0)
End If
End Sub
Private Sub Form1_MouseDown (ByVal sender As Object, ByVal e As System.Windows. Forms.MouseEven tArgs) Handles MyBase.MouseDow n
Mouse.X = e.X
Mouse.Y = e.Y
Drawing = True
If e.Button = MouseButtons.Le ft Then
MyPen = BlackInk
Else
MyPen = WhiteInk
End If
End Sub
Private Sub Form1_MouseMove (ByVal sender As Object, ByVal e As System.Windows. Forms.MouseEven tArgs) Handles MyBase.MouseMov e
If Drawing Then
' Use MyPen as both ink pens for normal use
FormGrx.DrawLin e(WhiteInk, Mouse.X, Mouse.Y, e.X, e.Y)
PageGrx.DrawLin e(BlackInk, Mouse.X, Mouse.Y, e.X, e.Y)
Mouse.X = e.X
Mouse.Y = e.Y
End If
End Sub
Private Sub Form1_MouseUp(B yVal sender As Object, ByVal e As System.Windows. Forms.MouseEven tArgs) Handles MyBase.MouseUp
Drawing = False
End Sub