I'm using VB Express 2010.
I'm creating an application for digital smartboards to write on it and send the data directly to a web service. I'm using an Panel with inkOverlay (Microsoft.ink) enabled.
Now I am trying to make an undo button. Here's a part my source code for now:
Expand|Select|Wrap|Line Numbers
- Imports Microsoft.Ink
- Imports System
- Imports System.Runtime.InteropServices
- Imports System.Drawing
- Imports System.Drawing.Imaging
- Public Class Form1
- Dim myInkOverlay As InkOverlay
- Dim History(1000000) As Image
- Dim HistoryId As Integer = 0
- Dim Developer As Boolean = True
- Sub New()
- InitializeComponent()
- End Sub
- 'Handle the form loading event by wiring up ink collection
- public Sub FormLoadHandler(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
- If (Developer = True) Then
- DeveloperField_HistoryId.Visible = True
- End If
- 'Create and enable the ink collecting Control
- myInkOverlay = New InkOverlay(Panel1)
- myInkOverlay.Enabled = True
- 'Form2.ShowDialog()
- 'Set the attributes of the ink collector
- SetAttributes()
- End Sub
- 'Creates controls for selecting raster operation
- Sub InitializeRasterOperations()
- 'Add all the types of Raster Operations to the groupbox for possible selection
- For Each rasterOpName As String In System.Enum.GetNames(GetType(RasterOperation))
- 'Create a new radio button
- Dim rasterButton As New RadioButton()
- rasterButton.Text = rasterOpName
- 'Default raster op is "Copy Pen"
- If rasterOpName = "CopyPen" Then
- rasterButton.Checked = True
- End If
- 'Add it to the flow layout panel
- 'FlowLayoutPanel1.Controls.Add(rasterButton)
- 'Add a handler to it
- AddHandler rasterButton.CheckedChanged, AddressOf RasterOpChosenHandler
- Next
- End Sub
- 'Handles selections of raster operation
- Sub RasterOpChosenHandler(ByVal sender As Object, ByVal e As EventArgs)
- 'Who has been chosen?
- Dim chosenButton As RadioButton = CType(sender, RadioButton)
- 'This will be called if checked or unchecked, so only assign on checked
- If chosenButton.Checked Then
- 'What's the RasterOperation value of selected button?
- Dim rasterOp = System.Enum.Parse(GetType(RasterOperation), chosenButton.Text)
- 'Set attribute
- myInkOverlay.DefaultDrawingAttributes.RasterOperation = rasterOp
- End If
- End Sub
- Sub SetAttributesHandler(ByVal sender As Object, ByVal e As EventArgs) Handles widthUpDown.ValueChanged, transparencyUpDown.ValueChanged, pressureSensitiveCheckbox.CheckedChanged, penTipRectangle.CheckedChanged, penTipEllipse.CheckedChanged, heightUpDown.ValueChanged, antiAliasCheckbox.CheckedChanged
- 'Can be called prior to myInkOverlay being initialized, so check if that's the case
- If myInkOverlay Is Nothing Then
- Return
- End If
- SetAttributes()
- End Sub
- 'Sets the major attributes of the ink overlay (minus color, raster op, and some rare properties
- Sub SetAttributes()
- 'Anti-aliasing
- If antiAliasCheckbox.Checked = True Then
- myInkOverlay.DefaultDrawingAttributes.AntiAliased = True
- Else
- myInkOverlay.DefaultDrawingAttributes.AntiAliased = False
- End If
- 'Pressure sensitivity
- If pressureSensitiveCheckbox.Checked = True Then
- myInkOverlay.DefaultDrawingAttributes.IgnorePressure = False
- Else
- myInkOverlay.DefaultDrawingAttributes.IgnorePressure = True
- End If
- 'Pen Tip
- If penTipRectangle.Checked = True Then
- myInkOverlay.DefaultDrawingAttributes.PenTip = PenTip.Rectangle
- Else
- myInkOverlay.DefaultDrawingAttributes.PenTip = PenTip.Ball
- End If
- 'Transparency
- myInkOverlay.DefaultDrawingAttributes.Transparency = transparencyUpDown.Value
- 'Height
- myInkOverlay.DefaultDrawingAttributes.Height = heightUpDown.Value
- 'Width
- myInkOverlay.DefaultDrawingAttributes.Width = widthUpDown.Value
- End Sub
- 'Handles "color" button
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
- 'Create a standard dialog
- Dim colorDialog As New ColorDialog()
- 'Set color to current color
- colorDialog.Color = myInkOverlay.DefaultDrawingAttributes.Color
- 'Show it
- If colorDialog.ShowDialog() = Windows.Forms.DialogResult.OK Then
- 'Set color to chosen
- myInkOverlay.DefaultDrawingAttributes.Color = colorDialog.Color
- End If
- End Sub
- Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
- myInkOverlay.DefaultDrawingAttributes.Color = Color.Red
- End Sub
- Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
- myInkOverlay.DefaultDrawingAttributes.Color = Color.Black
- End Sub
- Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
- myInkOverlay.DefaultDrawingAttributes.Color = Color.Yellow
- End Sub
- Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
- myInkOverlay.DefaultDrawingAttributes.Color = Color.Orange
- End Sub
- Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- Try
- Dim dir As String = Environ("USERPROFILE")
- If (FileIO.FileSystem.DirectoryExists(dir & "\My Documents")) Then
- dir = dir & "\My Documents"
- ElseIf (FileIO.FileSystem.DirectoryExists(dir & "\Documents")) Then
- dir = dir & "\Documents"
- End If
- If (FileIO.FileSystem.DirectoryExists(dir & "\LifeSchool")) Then
- Else
- FileIO.FileSystem.CreateDirectory(dir & "\LifeSchool")
- End If
- dir = dir & "\LifeSchool\"
- Dim file As String = dir & "temp.lss"
- If (FileIO.FileSystem.FileExists(file)) Then
- FileSystem.Kill(file)
- End If
- ScreenShotDemo.ScreenCapture.CaptureWindowToFile(Panel1.Handle, file, System.Drawing.Imaging.ImageFormat.Jpeg)
- Catch ex As Exception
- End Try
- End Sub
- Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
- myInkOverlay.DefaultDrawingAttributes.Color = Color.Pink
- End Sub
- Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
- myInkOverlay.DefaultDrawingAttributes.Color = Color.Purple
- End Sub
- Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
- myInkOverlay.DefaultDrawingAttributes.Color = Color.Gray
- End Sub
- Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
- myInkOverlay.DefaultDrawingAttributes.Color = Color.Green
- End Sub
- Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
- myInkOverlay.DefaultDrawingAttributes.Color = Color.Lime
- End Sub
- Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
- myInkOverlay.DefaultDrawingAttributes.Color = Color.Blue
- End Sub
- Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
- myInkOverlay.DefaultDrawingAttributes.Color = Color.Maroon
- End Sub
- Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
- myInkOverlay.DefaultDrawingAttributes.Color = Color.Teal
- End Sub
- Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
- If (FileIO.FileSystem.FileExists("Test.bmp")) Then
- FileSystem.Kill("Test.bmp")
- End If
- ScreenShotDemo.ScreenCapture.CaptureWindowToFile(Panel1.Handle, "Test.bmp", System.Drawing.Imaging.ImageFormat.Bmp)
- 'My.Computer.Network.UploadFile("Test.bmp", "http://www.tomttb.com/school/api/board/upload.php")
- 'Our postvars
- Dim strContents As String = ""
- Dim objReader As IO.StreamReader
- Try
- objReader = New IO.StreamReader("Test.bmp")
- strContents = objReader.ReadToEnd()
- objReader.Close()
- Catch Ex As Exception
- End Try
- Dim buffer As Byte() = System.Text.Encoding.ASCII.GetBytes("uid=" & USER.Text & "&file=" & strContents)
- 'Initialisation, we use localhost, change if appliable
- Dim WebReq As Net.HttpWebRequest = DirectCast(Net.WebRequest.Create("http://www.tomttb.com/school/api/board/upload.php"), Net.HttpWebRequest)
- 'Our method is post, otherwise the buffer (postvars) would be useless
- WebReq.Method = "POST"
- 'We use form contentType, for the postvars.
- WebReq.ContentType = "application/x-www-form-urlencoded"
- 'The length of the buffer (postvars) is used as contentlength.
- WebReq.ContentLength = buffer.Length
- 'We open a stream for writing the postvars
- Dim PostData As IO.Stream = WebReq.GetRequestStream()
- 'Now we write, and afterwards, we close. Closing is always important!
- PostData.Write(buffer, 0, buffer.Length)
- PostData.Close()
- 'Get the response handle, we have no true response yet!
- Dim WebResp As Net.HttpWebResponse = DirectCast(WebReq.GetResponse(), Net.HttpWebResponse)
- 'Let's show some information about the response
- MsgBox(WebResp.StatusCode)
- MsgBox(WebResp.Server)
- 'Now, we read the response (the string), and output it.
- Dim Answer As IO.Stream = WebResp.GetResponseStream()
- Dim _Answer As New IO.StreamReader(Answer)
- MsgBox(_Answer.ReadToEnd())
- End Sub
- Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
- If (myInkOverlay.Ink.Strokes.Count <> 0) Then
- myInkOverlay.Ink.DeleteStroke(myInkOverlay.Ink.Strokes.Item(myInkOverlay.Ink.Strokes.Count - 1))
- End If
- End Sub
- Private Sub Panel1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
- DeveloperField_HistoryId.Text = myInkOverlay.Ink.Strokes.Count
- End Sub
- End Class