I have the following code which allows freehand drawing using a mouse. It uses a panel as drawing surface. I will add the ability to load background images on the panel so can draw on that bmp.
Now after all the drawing, I want to ensure its one image, a bmp, copy to clipboard then paste it into a richtextbox on another form in the program.
Now attempting this I have tried several approaches. None have worked at all.
The online tutorials or samples to study I can find are many years old and many version of basic ago. None work of course.
Here is my base code for drawing.
Any advice, or directing me to a tutorial, sample, or a reference book would be greatly appreciated.
From what I read, this should work. There was some literatur eon not drawing to a control but rather to a bmp using the controls paint event. This was what I could get to work for drawing.
Imports System.Math
Public Class Form1
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal cButtons As Integer, ByVal dwExtraInfo As Integer)
Private Const MOUSEEVENTF_MOVE As Integer = &H1 ' mouse move
Private Const MOUSEEVENTF_LEFTDOWN As Integer = &H2 ' left button down
Private Const MOUSEEVENTF_LEFTUP As Integer = &H4 ' left button up
Private Const MOUSEEVENTF_RIGHTDOWN As Integer = &H8 ' right button down
Private Const MOUSEEVENTF_RIGHTUP As Integer = &H10 ' right button up
Private Const MOUSEEVENTF_MIDDLEDOWN As Integer = &H20 ' middle button down
Private Const MOUSEEVENTF_MIDDLEUP As Integer = &H40 ' middle button up
Private Const MOUSEEVENTF_WHEEL As Integer = &H800 ' wheel button rolled
Private Const MOUSEEVENTF_ABSOLUTE As Integer = &H8000 ' absolute move
Private m_Drawing As Boolean = False
Private m_LastPoint As Point = Nothing
' Start drawing by hand using mouse.
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseDown
m_Drawing = True
m_LastPoint = New Point(e.X, e.Y)
Dim gr As Graphics = Panel1.CreateGraphics()
End Sub
' Continue drawing.
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseMove
If Not m_Drawing Then Exit Sub
Dim gr As Graphics = Panel1.CreateGraphics()
gr.DrawLine(Pens.Blue, m_LastPoint, New Point(e.X, e.Y))
m_LastPoint = New Point(e.X, e.Y)
End Sub
' Stop drawing.
Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseUp
m_Drawing = False
End Sub
¡®to refresh the panel, i.e start over
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Panel1.Refresh()
End Sub
¡® exit program
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()
End Sub
End Class
Something like this can be added later to load a bmp as background image for the panel.
' panel1.BackgroundImage = My.Resources.FACE
¡® or could use this next line to let the panel size to loaded bmp size
' panel1.Size = panel1.BackgroundImage.Size