By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,166 Members | 1,575 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,166 IT Pros & Developers. It's quick & easy.

How to "form1.line (x1,y2)-(x2,y2)" in VB.NET

P: n/a
Dear All,
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?

Best regards,
Boki.
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Boki

http://communities.microsoft.com/new...idbey&slcid=us

Maybe a better place for this question?

Cor
Nov 21 '05 #2

P: n/a

"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(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Page = New Bitmap(Me.ClientSize.Width, Me.ClientSize.Height)
ResetGraphics()
End Sub

Private Sub ResetGraphics()
If Not PageGrx Is Nothing Then PageGrx.Dispose()
PageGrx = Graphics.FromImage(Page)
PageGrx.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
If Not FormGrx Is Nothing Then FormGrx.Dispose()
FormGrx = Me.CreateGraphics
FormGrx.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
End Sub

Private Sub Form1_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.SizeChanged
' 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.ClientSize.Width, Me.ClientSize.Height)
Dim grx As Graphics = Graphics.FromImage(tmp)
grx.DrawImageUnscaled(Page, 0, 0)
grx.Dispose()
Page.Dispose()
' Start using new image
Page = tmp
ResetGraphics()

End Sub

Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
If Not FormGrx Is Nothing Then
FormGrx.DrawImageUnscaled(Page, 0, 0)
End If
End Sub

Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
Mouse.X = e.X
Mouse.Y = e.Y
Drawing = True
If e.Button = MouseButtons.Left Then
MyPen = BlackInk
Else
MyPen = WhiteInk
End If

End Sub

Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
If Drawing Then
' Use MyPen as both ink pens for normal use
FormGrx.DrawLine(WhiteInk, Mouse.X, Mouse.Y, e.X, e.Y)
PageGrx.DrawLine(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(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp
Drawing = False
End Sub
Nov 21 '05 #3

P: n/a
"Cor Ligthert" <no************@planet.nl> wrote in message news:<#n**************@TK2MSFTNGP09.phx.gbl>...
Boki

http://communities.microsoft.com/new...idbey&slcid=us

Maybe a better place for this question?

Cor


Got it, thank you for information. : )

Best regards,
Boki.
Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.