Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class frmCanvas
- Public startX As Integer = 0
- Public startY As Integer = 0
- Private endX As Integer = 0
- Private endY As Integer = 0
- Private BMAP As Bitmap
- Private isMouseDown As Boolean = False
- Dim addImage As Boolean = False
- Dim line As Boolean = False
- Dim clearCanvas As Boolean = False
- Dim draw As Boolean = False
- Dim brushSize As Integer = 20
- Public brushColor As Brush = Brushes.Black
- Dim eraserSize As Integer = 30
- Dim addLabel As Boolean = False
- Public lbl As New Label
- Dim MousePosX As Single, MousePosY As Single
- Public lblText As String
- Public lblColor As Color
- Private Sub Canvas_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Canvas.MouseClick
- If addImage = True Then
- Dim g2 As Graphics = Graphics.FromImage(BMAP)
- Canvas.Image = BMAP
- g2.FillRectangle(Brushes.White, startX, startY, e.X, e.Y)
- Dim g As Graphics = Graphics.FromImage(BMAP)
- g.DrawImage(PictureBox1.Image, startX, startY, e.X, e.Y)
- Canvas.Image = BMAP
- End If
- If addLabel = True Then
- frmLabelText.Show()
- lbl.Text = lblText
- lbl.ForeColor = lblColor
- AddHandler lbl.Click, AddressOf Me.lbl_Click
- lbl.BringToFront()
- Canvas.Controls.Add(lbl)
- End If
- If clearCanvas = True Then
- Dim g2 As Graphics = Graphics.FromImage(BMAP)
- Canvas.Image = BMAP
- g2.FillRectangle(Brushes.White, startX, startY, e.X, e.Y)
- Dim g As Graphics = Graphics.FromImage(BMAP)
- Canvas.Image = BMAP
- g.DrawLine(Pens.White, startX, startY, e.X, e.Y)
- End If
- End Sub
- Sub lbl_Click()
- If clearCanvas = True Then
- lbl.Text = ""
- End If
- End Sub
- Private Sub Canvas_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Canvas.MouseDown
- isMouseDown = True
- startX = e.X
- startY = e.Y
- End Sub
- Private Sub Canvas_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Canvas.MouseMove
- lblMousePos.Text = "X Pos: " & e.X & ", Y Pos: " & e.Y
- If isMouseDown = True Then
- If line = True Then
- Dim g As Graphics = Graphics.FromImage(BMAP)
- g.DrawLine(New Pen(Me.Canvas.BackColor), startX, startY, endX, endY)
- Canvas.Image = BMAP
- g.DrawLine(Pens.Black, startX, startY, e.X, e.Y)
- Canvas.Image = BMAP
- ElseIf addImage = True Then
- Dim g As Graphics = Graphics.FromImage(BMAP)
- Canvas.Image = BMAP
- g.FillRectangle(Brushes.AliceBlue, startX, startY, e.X, e.Y)
- ElseIf clearCanvas = True Then
- Dim g As Graphics = Graphics.FromImage(BMAP)
- Canvas.Image = BMAP
- g.FillRectangle(Brushes.White, e.X, e.Y, eraserSize, eraserSize)
- ElseIf draw = True Then
- Dim g As Graphics = Graphics.FromImage(BMAP)
- Canvas.Image = BMAP
- g.FillRectangle(brushColor, e.X, e.Y, brushSize, brushSize)
- ElseIf addLabel = True Then
- lbl.AutoSize = True
- End If
- End If
- End Sub
- Private Sub frmCanvas_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
- 'Dim ms As New IO.MemoryStream
- 'Canvas.Image.Save(ms, Drawing.Imaging.ImageFormat.Png)
- 'Dim s As String = System.Text.Encoding.Default.GetString(ms.ToArray)
- 'My.Settings.pbImage = s
- End Sub
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- 'If My.Settings.pbImage <> "" Then
- ' Dim b() As Byte = System.Text.Encoding.Default.GetBytes(My.Settings.pbImage)
- ' Canvas.Image = Image.FromStream(New IO.MemoryStream(b))
- 'End If
- Me.Size = New Size(818, 587)
- BMAP = New Bitmap(Canvas.Width, Canvas.Height)
- End Sub
- Private Sub Canvas_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Canvas.MouseUp
- endX = e.X
- endY = e.Y
- isMouseDown = False
- End Sub
- Private Sub SaveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripMenuItem.Click
- Dim saveBitMap As New SaveFileDialog
- saveBitMap.Filter = "(*.png) | *.png"
- saveBitMap.ShowDialog()
- If saveBitMap.FileName <> Nothing Then
- BMAP.Save(saveBitMap.FileName)
- End If
- End Sub
- Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
- Dim openBitMap As New OpenFileDialog
- openBitMap.Filter = "(*.png) | *.png"
- openBitMap.ShowDialog()
- If openBitMap.FileName <> Nothing Then
- BMAP = Image.FromFile(openBitMap.FileName)
- Canvas.Image = BMAP
- End If
- End Sub
- Private Sub btnCircle_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCircle.Click
- Dim openImage As New OpenFileDialog
- openImage.ShowDialog()
- If openImage.FileName <> Nothing Then
- PictureBox1.Image = Image.FromFile(openImage.FileName)
- End If
- addImage = True
- line = False
- clearCanvas = False
- draw = False
- addLabel = False
- End Sub
- Private Sub btnLine_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLine.Click
- line = True
- addImage = False
- clearCanvas = False
- draw = False
- addLabel = False
- End Sub
- Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picPencil.Click
- btnLine.PerformClick()
- picPencil.BackColor = Color.Lime
- picImage.BackColor = Color.ForestGreen
- picClear.BackColor = Color.ForestGreen
- picDraw.BackColor = Color.ForestGreen
- picAddLabel.BackColor = Color.ForestGreen
- End Sub
- Private Sub PictureBox3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picImage.Click
- btnCircle.PerformClick()
- picImage.BackColor = Color.Lime
- picPencil.BackColor = Color.ForestGreen
- picClear.BackColor = Color.ForestGreen
- picDraw.BackColor = Color.ForestGreen
- picAddLabel.BackColor = Color.ForestGreen
- End Sub
- Private Sub picClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picClear.Click
- picClear.BackColor = Color.Lime
- picImage.BackColor = Color.ForestGreen
- picPencil.BackColor = Color.ForestGreen
- picDraw.BackColor = Color.ForestGreen
- picAddLabel.BackColor = Color.ForestGreen
- clearCanvas = True
- addImage = False
- line = False
- draw = False
- addLabel = False
- End Sub
- Private Sub ClearCanvasToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearCanvasToolStripMenuItem.Click
- Dim g As Graphics = Graphics.FromImage(BMAP)
- Canvas.Image = BMAP
- g.Clear(Color.White)
- End Sub
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
- Me.Size = New Size(828, 833)
- End Sub
- Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTools.Click
- Static pressed As Integer = 0
- If pressed Mod 2 = 0 Then
- Me.Size = New Size(818, 745)
- pressed += 1
- btnTools.Text = "Hide ToolBox"
- Else
- Me.Size = New Size(818, 587)
- pressed += 1
- btnTools.Text = "Show ToolBox"
- End If
- End Sub
- Private Sub picDraw_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picDraw.Click
- picDraw.BackColor = Color.Lime
- picClear.BackColor = Color.ForestGreen
- picImage.BackColor = Color.ForestGreen
- picPencil.BackColor = Color.ForestGreen
- picAddLabel.BackColor = Color.ForestGreen
- draw = True
- clearCanvas = False
- addImage = False
- line = False
- addLabel = False
- End Sub
- Private Sub ToolStripMenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem2.Click
- brushSize = 10
- End Sub
- Private Sub ToolStripMenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem3.Click
- brushSize = 20
- End Sub
- Private Sub ToolStripMenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem4.Click
- brushSize = 30
- End Sub
- Private Sub ToolStripMenuItem5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem5.Click
- brushSize = 40
- End Sub
- Private Sub ToolStripMenuItem6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem6.Click
- brushSize = 50
- End Sub
- Private Sub ToolStripMenuItem7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem7.Click
- brushSize = 60
- End Sub
- Private Sub PictureBox3_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picColor.Click
- picColor.BackColor = Color.Lime
- frmColors.Show()
- End Sub
- Private Sub ToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem1.Click
- eraserSize = 10
- End Sub
- Private Sub ToolStripMenuItem8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem8.Click
- eraserSize = 20
- End Sub
- Private Sub ToolStripMenuItem9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem9.Click
- eraserSize = 30
- End Sub
- Private Sub ToolStripMenuItem10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem10.Click
- eraserSize = 40
- End Sub
- Private Sub ToolStripMenuItem11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem11.Click
- eraserSize = 50
- End Sub
- Private Sub ToolStripMenuItem12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem12.Click
- eraserSize = 60
- End Sub
- Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
- Application.Exit()
- End Sub
- Private Sub PictureBox3_Click_2(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picAddLabel.Click
- picAddLabel.BackColor = Color.Lime
- picDraw.BackColor = Color.ForestGreen
- picClear.BackColor = Color.ForestGreen
- picImage.BackColor = Color.ForestGreen
- picPencil.BackColor = Color.ForestGreen
- addLabel = True
- draw = False
- clearCanvas = False
- addImage = False
- line = False
- End Sub
- Private Sub ToolStripMenuItem13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem13.Click
- lbl.Font = New Font("Segoe UI", 10)
- End Sub
- Private Sub ToolStripMenuItem14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem14.Click
- lbl.Font = New Font("Segoe UI", 20)
- End Sub
- Private Sub ToolStripMenuItem15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem15.Click
- lbl.Font = New Font("Segoe UI", 30)
- End Sub
- Private Sub ToolStripMenuItem16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem16.Click
- lbl.Font = New Font("Segoe UI", 40)
- End Sub
- Private Sub ToolStripMenuItem17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem17.Click
- lbl.Font = New Font("Segoe UI", 50)
- End Sub
- Private Sub ToolStripMenuItem18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem18.Click
- lbl.Font = New Font("Segoe UI", 60)
- End Sub
- Private Sub picTools_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picTools.Click
- btnTools.PerformClick()
- End Sub
- Private Sub picTools_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles picTools.MouseEnter
- picTools.BackColor = Color.ForestGreen
- End Sub
- Private Sub picTools_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles picTools.MouseHover
- ToolTip1.SetToolTip(Me.picTools, "Show/Hide Tools")
- End Sub
- Private Sub picTools_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles picTools.MouseLeave
- picTools.BackColor = Color.Lime
- End Sub
- Private Sub frmCanvas_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
- If e.Button = 0 Then
- MousePosX = e.X
- MousePosY = e.Y
- Else
- Me.Left = Me.Left + (e.X - MousePosX)
- Me.Top = Me.Top + (e.Y - MousePosY)
- End If
- End Sub
- Private Sub MenuStrip1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MenuStrip1.MouseMove
- If e.Button = 0 Then
- MousePosX = e.X
- MousePosY = e.Y
- Else
- Me.Left = Me.Left + (e.X - MousePosX)
- Me.Top = Me.Top + (e.Y - MousePosY)
- End If
- End Sub
- Private Sub MenuStrip2_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MenuStrip2.MouseMove
- If e.Button = 0 Then
- MousePosX = e.X
- MousePosY = e.Y
- Else
- Me.Left = Me.Left + (e.X - MousePosX)
- Me.Top = Me.Top + (e.Y - MousePosY)
- End If
- End Sub
- Private Sub PictureBox8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox8.Click
- Application.Exit()
- End Sub
- Private Sub lblMousePos_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblMousePos.Click
- End Sub
- Private Sub HelpToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HelpToolStripMenuItem.Click
- frmHelp.Show()
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement