M
Martin Horn
Hi all,
I'm adding basic drawing capability to an application that I am writing, and
I have been having problems with making the graphics output persist when the
application is re-sized,covered etc.
This is the solution I have come up with, but it seems a bit convoluted.
Before I get too far into the development of the program, could someone cast
an eye over my code and tell me if I have approached it in the correct way,
or suggest a better solution.
Many thanks,
Martin Horn. (See below for my code)
Imports System.Windows.Forms
Public Class ComplexInscriptionDesignerForm
Private Drawing As Boolean = False
Private OldX As Integer = 0
Private OldY As Integer = 0
Private PaintObject As Object
Private CanvasBM As System.Drawing.Bitmap
Private Canvas As Graphics
Private Sub PicCanvas_MouseDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles PicCanvas.MouseDown
Drawing = True
OldX = e.X
OldY = e.Y
End Sub
Private Sub PicCanvas_MouseMove(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles PicCanvas.MouseMove
If Drawing Then
Canvas.DrawLine(Pens.Black, OldX, OldY, e.X, e.Y)
OldX = e.X
OldY = e.Y
PicCanvas.Invalidate()
End If
End Sub
Private Sub PicCanvas_MouseUp(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles PicCanvas.MouseUp
Drawing = False
End Sub
Private Sub PicCanvas_Paint(ByVal sender As Object, _
ByVal e As System.Windows.Forms.PaintEventArgs) _
Handles PicCanvas.Paint
e.Graphics.DrawImageUnscaled(CanvasBM, 0, 0)
End Sub
Private Sub ComplexInscriptionDesignerForm_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
CanvasBM = New System.Drawing.Bitmap( _
PicCanvas.ClientSize.Width, _
PicCanvas.ClientSize.Height)
Canvas = Graphics.FromImage(CanvasBM)
End Sub
End Class
I'm adding basic drawing capability to an application that I am writing, and
I have been having problems with making the graphics output persist when the
application is re-sized,covered etc.
This is the solution I have come up with, but it seems a bit convoluted.
Before I get too far into the development of the program, could someone cast
an eye over my code and tell me if I have approached it in the correct way,
or suggest a better solution.
Many thanks,
Martin Horn. (See below for my code)
Imports System.Windows.Forms
Public Class ComplexInscriptionDesignerForm
Private Drawing As Boolean = False
Private OldX As Integer = 0
Private OldY As Integer = 0
Private PaintObject As Object
Private CanvasBM As System.Drawing.Bitmap
Private Canvas As Graphics
Private Sub PicCanvas_MouseDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles PicCanvas.MouseDown
Drawing = True
OldX = e.X
OldY = e.Y
End Sub
Private Sub PicCanvas_MouseMove(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles PicCanvas.MouseMove
If Drawing Then
Canvas.DrawLine(Pens.Black, OldX, OldY, e.X, e.Y)
OldX = e.X
OldY = e.Y
PicCanvas.Invalidate()
End If
End Sub
Private Sub PicCanvas_MouseUp(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles PicCanvas.MouseUp
Drawing = False
End Sub
Private Sub PicCanvas_Paint(ByVal sender As Object, _
ByVal e As System.Windows.Forms.PaintEventArgs) _
Handles PicCanvas.Paint
e.Graphics.DrawImageUnscaled(CanvasBM, 0, 0)
End Sub
Private Sub ComplexInscriptionDesignerForm_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
CanvasBM = New System.Drawing.Bitmap( _
PicCanvas.ClientSize.Width, _
PicCanvas.ClientSize.Height)
Canvas = Graphics.FromImage(CanvasBM)
End Sub
End Class