Advertisement
TermSpar

PH BitTools

Mar 5th, 2016
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 15.86 KB | None | 0 0
  1. Public Class frmCanvas
  2.     Public startX As Integer = 0
  3.     Public startY As Integer = 0
  4.     Private endX As Integer = 0
  5.     Private endY As Integer = 0
  6.     Private BMAP As Bitmap
  7.     Private isMouseDown As Boolean = False
  8.     Dim addImage As Boolean = False
  9.     Dim line As Boolean = False
  10.     Dim clearCanvas As Boolean = False
  11.     Dim draw As Boolean = False
  12.     Dim brushSize As Integer = 20
  13.     Public brushColor As Brush = Brushes.Black
  14.     Dim eraserSize As Integer = 30
  15.     Dim addLabel As Boolean = False
  16.     Public lbl As New Label
  17.     Dim MousePosX As Single, MousePosY As Single
  18.     Public lblText As String
  19.     Public lblColor As Color
  20.  
  21.         Private Sub Canvas_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Canvas.MouseClick
  22.             If addImage = True Then
  23.                 Dim g2 As Graphics = Graphics.FromImage(BMAP)
  24.                 Canvas.Image = BMAP
  25.                 g2.FillRectangle(Brushes.White, startX, startY, e.X, e.Y)
  26.                 Dim g As Graphics = Graphics.FromImage(BMAP)
  27.                 g.DrawImage(PictureBox1.Image, startX, startY, e.X, e.Y)
  28.                 Canvas.Image = BMAP
  29.             End If
  30.         If addLabel = True Then
  31.             frmLabelText.Show()
  32.             lbl.Text = lblText
  33.             lbl.ForeColor = lblColor
  34.             AddHandler lbl.Click, AddressOf Me.lbl_Click
  35.             lbl.BringToFront()
  36.             Canvas.Controls.Add(lbl)
  37.         End If
  38.             If clearCanvas = True Then
  39.                 Dim g2 As Graphics = Graphics.FromImage(BMAP)
  40.                 Canvas.Image = BMAP
  41.                 g2.FillRectangle(Brushes.White, startX, startY, e.X, e.Y)
  42.                 Dim g As Graphics = Graphics.FromImage(BMAP)
  43.                 Canvas.Image = BMAP
  44.                 g.DrawLine(Pens.White, startX, startY, e.X, e.Y)
  45.             End If
  46.     End Sub
  47.  
  48.     Sub lbl_Click()
  49.         If clearCanvas = True Then
  50.             lbl.Text = ""
  51.         End If
  52.     End Sub
  53.  
  54.         Private Sub Canvas_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Canvas.MouseDown
  55.             isMouseDown = True
  56.             startX = e.X
  57.             startY = e.Y
  58.         End Sub
  59.  
  60.         Private Sub Canvas_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Canvas.MouseMove
  61.         lblMousePos.Text = "X Pos: " & e.X & ", Y Pos: " & e.Y
  62.         If isMouseDown = True Then
  63.             If line = True Then
  64.                 Dim g As Graphics = Graphics.FromImage(BMAP)
  65.                 g.DrawLine(New Pen(Me.Canvas.BackColor), startX, startY, endX, endY)
  66.                 Canvas.Image = BMAP
  67.                 g.DrawLine(Pens.Black, startX, startY, e.X, e.Y)
  68.                 Canvas.Image = BMAP
  69.             ElseIf addImage = True Then
  70.                 Dim g As Graphics = Graphics.FromImage(BMAP)
  71.                 Canvas.Image = BMAP
  72.                 g.FillRectangle(Brushes.AliceBlue, startX, startY, e.X, e.Y)
  73.             ElseIf clearCanvas = True Then
  74.                 Dim g As Graphics = Graphics.FromImage(BMAP)
  75.                 Canvas.Image = BMAP
  76.                 g.FillRectangle(Brushes.White, e.X, e.Y, eraserSize, eraserSize)
  77.             ElseIf draw = True Then
  78.                 Dim g As Graphics = Graphics.FromImage(BMAP)
  79.                 Canvas.Image = BMAP
  80.                 g.FillRectangle(brushColor, e.X, e.Y, brushSize, brushSize)
  81.             ElseIf addLabel = True Then
  82.                 lbl.AutoSize = True
  83.             End If
  84.         End If
  85.         End Sub
  86.  
  87.         Private Sub frmCanvas_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
  88.             'Dim ms As New IO.MemoryStream
  89.             'Canvas.Image.Save(ms, Drawing.Imaging.ImageFormat.Png)
  90.             'Dim s As String = System.Text.Encoding.Default.GetString(ms.ToArray)
  91.             'My.Settings.pbImage = s
  92.         End Sub
  93.  
  94.         Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  95.             'If My.Settings.pbImage <> "" Then
  96.             '    Dim b() As Byte = System.Text.Encoding.Default.GetBytes(My.Settings.pbImage)
  97.             '    Canvas.Image = Image.FromStream(New IO.MemoryStream(b))
  98.             'End If
  99.             Me.Size = New Size(818, 587)
  100.             BMAP = New Bitmap(Canvas.Width, Canvas.Height)
  101.         End Sub
  102.  
  103.         Private Sub Canvas_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Canvas.MouseUp
  104.             endX = e.X
  105.             endY = e.Y
  106.             isMouseDown = False
  107.         End Sub
  108.  
  109.         Private Sub SaveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripMenuItem.Click
  110.             Dim saveBitMap As New SaveFileDialog
  111.             saveBitMap.Filter = "(*.png) | *.png"
  112.             saveBitMap.ShowDialog()
  113.             If saveBitMap.FileName <> Nothing Then
  114.                 BMAP.Save(saveBitMap.FileName)
  115.             End If
  116.         End Sub
  117.  
  118.         Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
  119.             Dim openBitMap As New OpenFileDialog
  120.             openBitMap.Filter = "(*.png) | *.png"
  121.             openBitMap.ShowDialog()
  122.             If openBitMap.FileName <> Nothing Then
  123.                 BMAP = Image.FromFile(openBitMap.FileName)
  124.                 Canvas.Image = BMAP
  125.             End If
  126.         End Sub
  127.  
  128.         Private Sub btnCircle_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCircle.Click
  129.             Dim openImage As New OpenFileDialog
  130.             openImage.ShowDialog()
  131.             If openImage.FileName <> Nothing Then
  132.                 PictureBox1.Image = Image.FromFile(openImage.FileName)
  133.             End If
  134.             addImage = True
  135.             line = False
  136.             clearCanvas = False
  137.             draw = False
  138.             addLabel = False
  139.         End Sub
  140.  
  141.         Private Sub btnLine_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLine.Click
  142.             line = True
  143.             addImage = False
  144.             clearCanvas = False
  145.             draw = False
  146.             addLabel = False
  147.         End Sub
  148.  
  149.         Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picPencil.Click
  150.             btnLine.PerformClick()
  151.             picPencil.BackColor = Color.Lime
  152.             picImage.BackColor = Color.ForestGreen
  153.             picClear.BackColor = Color.ForestGreen
  154.             picDraw.BackColor = Color.ForestGreen
  155.             picAddLabel.BackColor = Color.ForestGreen
  156.         End Sub
  157.  
  158.         Private Sub PictureBox3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picImage.Click
  159.             btnCircle.PerformClick()
  160.             picImage.BackColor = Color.Lime
  161.             picPencil.BackColor = Color.ForestGreen
  162.             picClear.BackColor = Color.ForestGreen
  163.             picDraw.BackColor = Color.ForestGreen
  164.             picAddLabel.BackColor = Color.ForestGreen
  165.         End Sub
  166.  
  167.         Private Sub picClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picClear.Click
  168.             picClear.BackColor = Color.Lime
  169.             picImage.BackColor = Color.ForestGreen
  170.             picPencil.BackColor = Color.ForestGreen
  171.             picDraw.BackColor = Color.ForestGreen
  172.             picAddLabel.BackColor = Color.ForestGreen
  173.             clearCanvas = True
  174.             addImage = False
  175.             line = False
  176.             draw = False
  177.             addLabel = False
  178.         End Sub
  179.  
  180.         Private Sub ClearCanvasToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearCanvasToolStripMenuItem.Click
  181.             Dim g As Graphics = Graphics.FromImage(BMAP)
  182.             Canvas.Image = BMAP
  183.             g.Clear(Color.White)
  184.         End Sub
  185.  
  186.         Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
  187.             Me.Size = New Size(828, 833)
  188.         End Sub
  189.  
  190.         Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTools.Click
  191.             Static pressed As Integer = 0
  192.             If pressed Mod 2 = 0 Then
  193.                 Me.Size = New Size(818, 745)
  194.                 pressed += 1
  195.                 btnTools.Text = "Hide ToolBox"
  196.             Else
  197.                 Me.Size = New Size(818, 587)
  198.                 pressed += 1
  199.                 btnTools.Text = "Show ToolBox"
  200.             End If
  201.  
  202.         End Sub
  203.  
  204.         Private Sub picDraw_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picDraw.Click
  205.             picDraw.BackColor = Color.Lime
  206.             picClear.BackColor = Color.ForestGreen
  207.             picImage.BackColor = Color.ForestGreen
  208.             picPencil.BackColor = Color.ForestGreen
  209.             picAddLabel.BackColor = Color.ForestGreen
  210.             draw = True
  211.             clearCanvas = False
  212.             addImage = False
  213.             line = False
  214.             addLabel = False
  215.         End Sub
  216.  
  217.         Private Sub ToolStripMenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem2.Click
  218.             brushSize = 10
  219.         End Sub
  220.  
  221.         Private Sub ToolStripMenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem3.Click
  222.             brushSize = 20
  223.         End Sub
  224.  
  225.         Private Sub ToolStripMenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem4.Click
  226.             brushSize = 30
  227.         End Sub
  228.  
  229.         Private Sub ToolStripMenuItem5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem5.Click
  230.             brushSize = 40
  231.         End Sub
  232.  
  233.         Private Sub ToolStripMenuItem6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem6.Click
  234.             brushSize = 50
  235.         End Sub
  236.  
  237.         Private Sub ToolStripMenuItem7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem7.Click
  238.             brushSize = 60
  239.         End Sub
  240.  
  241.         Private Sub PictureBox3_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picColor.Click
  242.             picColor.BackColor = Color.Lime
  243.             frmColors.Show()
  244.         End Sub
  245.  
  246.         Private Sub ToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem1.Click
  247.             eraserSize = 10
  248.         End Sub
  249.  
  250.         Private Sub ToolStripMenuItem8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem8.Click
  251.             eraserSize = 20
  252.         End Sub
  253.  
  254.         Private Sub ToolStripMenuItem9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem9.Click
  255.             eraserSize = 30
  256.         End Sub
  257.  
  258.         Private Sub ToolStripMenuItem10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem10.Click
  259.             eraserSize = 40
  260.         End Sub
  261.  
  262.         Private Sub ToolStripMenuItem11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem11.Click
  263.             eraserSize = 50
  264.         End Sub
  265.  
  266.         Private Sub ToolStripMenuItem12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem12.Click
  267.             eraserSize = 60
  268.         End Sub
  269.  
  270.         Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
  271.             Application.Exit()
  272.         End Sub
  273.  
  274.         Private Sub PictureBox3_Click_2(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picAddLabel.Click
  275.             picAddLabel.BackColor = Color.Lime
  276.             picDraw.BackColor = Color.ForestGreen
  277.             picClear.BackColor = Color.ForestGreen
  278.             picImage.BackColor = Color.ForestGreen
  279.             picPencil.BackColor = Color.ForestGreen
  280.             addLabel = True
  281.             draw = False
  282.             clearCanvas = False
  283.             addImage = False
  284.             line = False
  285.         End Sub
  286.  
  287.         Private Sub ToolStripMenuItem13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem13.Click
  288.             lbl.Font = New Font("Segoe UI", 10)
  289.         End Sub
  290.  
  291.         Private Sub ToolStripMenuItem14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem14.Click
  292.             lbl.Font = New Font("Segoe UI", 20)
  293.         End Sub
  294.  
  295.         Private Sub ToolStripMenuItem15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem15.Click
  296.             lbl.Font = New Font("Segoe UI", 30)
  297.         End Sub
  298.  
  299.         Private Sub ToolStripMenuItem16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem16.Click
  300.             lbl.Font = New Font("Segoe UI", 40)
  301.         End Sub
  302.  
  303.         Private Sub ToolStripMenuItem17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem17.Click
  304.             lbl.Font = New Font("Segoe UI", 50)
  305.         End Sub
  306.  
  307.         Private Sub ToolStripMenuItem18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem18.Click
  308.             lbl.Font = New Font("Segoe UI", 60)
  309.         End Sub
  310.  
  311.         Private Sub picTools_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picTools.Click
  312.             btnTools.PerformClick()
  313.         End Sub
  314.  
  315.         Private Sub picTools_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles picTools.MouseEnter
  316.             picTools.BackColor = Color.ForestGreen
  317.         End Sub
  318.  
  319.         Private Sub picTools_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles picTools.MouseHover
  320.             ToolTip1.SetToolTip(Me.picTools, "Show/Hide Tools")
  321.         End Sub
  322.  
  323.         Private Sub picTools_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles picTools.MouseLeave
  324.             picTools.BackColor = Color.Lime
  325.         End Sub
  326.  
  327.         Private Sub frmCanvas_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
  328.             If e.Button = 0 Then
  329.                 MousePosX = e.X
  330.                 MousePosY = e.Y
  331.             Else
  332.                 Me.Left = Me.Left + (e.X - MousePosX)
  333.                 Me.Top = Me.Top + (e.Y - MousePosY)
  334.             End If
  335.         End Sub
  336.  
  337.         Private Sub MenuStrip1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MenuStrip1.MouseMove
  338.             If e.Button = 0 Then
  339.                 MousePosX = e.X
  340.                 MousePosY = e.Y
  341.             Else
  342.                 Me.Left = Me.Left + (e.X - MousePosX)
  343.                 Me.Top = Me.Top + (e.Y - MousePosY)
  344.             End If
  345.         End Sub
  346.  
  347.         Private Sub MenuStrip2_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MenuStrip2.MouseMove
  348.             If e.Button = 0 Then
  349.                 MousePosX = e.X
  350.                 MousePosY = e.Y
  351.             Else
  352.                 Me.Left = Me.Left + (e.X - MousePosX)
  353.                 Me.Top = Me.Top + (e.Y - MousePosY)
  354.             End If
  355.         End Sub
  356.  
  357.         Private Sub PictureBox8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox8.Click
  358.             Application.Exit()
  359.         End Sub
  360.  
  361.     Private Sub lblMousePos_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblMousePos.Click
  362.  
  363.     End Sub
  364.  
  365.     Private Sub HelpToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HelpToolStripMenuItem.Click
  366.         frmHelp.Show()
  367.     End Sub
  368. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement