473,811 Members | 3,135 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Create undo button in simple drawing application

5 New Member
Hi,

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
  1. Imports Microsoft.Ink
  2. Imports System
  3. Imports System.Runtime.InteropServices
  4. Imports System.Drawing
  5. Imports System.Drawing.Imaging
  6.  
  7. Public Class Form1
  8.     Dim myInkOverlay As InkOverlay
  9.     Dim History(1000000) As Image
  10.     Dim HistoryId As Integer = 0
  11.  
  12.     Dim Developer As Boolean = True
  13.  
  14.     Sub New()
  15.         InitializeComponent()
  16.     End Sub
  17.  
  18.     'Handle the form loading event by wiring up ink collection
  19.     public Sub FormLoadHandler(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
  20.  
  21.         If (Developer = True) Then
  22.             DeveloperField_HistoryId.Visible = True
  23.         End If
  24.  
  25.         'Create and enable the ink collecting Control
  26.         myInkOverlay = New InkOverlay(Panel1)
  27.         myInkOverlay.Enabled = True
  28.         'Form2.ShowDialog()
  29.         'Set the attributes of the ink collector
  30.         SetAttributes()
  31.     End Sub
  32.  
  33.  
  34.     'Creates controls for selecting raster operation
  35.     Sub InitializeRasterOperations()
  36.         'Add all the types of Raster Operations to the groupbox for possible selection
  37.         For Each rasterOpName As String In System.Enum.GetNames(GetType(RasterOperation))
  38.             'Create a new radio button
  39.             Dim rasterButton As New RadioButton()
  40.             rasterButton.Text = rasterOpName
  41.  
  42.             'Default raster op is "Copy Pen"
  43.             If rasterOpName = "CopyPen" Then
  44.                 rasterButton.Checked = True
  45.             End If
  46.  
  47.             'Add it to the flow layout panel
  48.             'FlowLayoutPanel1.Controls.Add(rasterButton)
  49.  
  50.             'Add a handler to it
  51.             AddHandler rasterButton.CheckedChanged, AddressOf RasterOpChosenHandler
  52.         Next
  53.     End Sub
  54.  
  55.     'Handles selections of raster operation
  56.     Sub RasterOpChosenHandler(ByVal sender As Object, ByVal e As EventArgs)
  57.         'Who has been chosen?
  58.         Dim chosenButton As RadioButton = CType(sender, RadioButton)
  59.         'This will be called if checked or unchecked, so only assign on checked
  60.         If chosenButton.Checked Then
  61.             'What's the RasterOperation value of selected button?
  62.             Dim rasterOp = System.Enum.Parse(GetType(RasterOperation), chosenButton.Text)
  63.             'Set attribute
  64.             myInkOverlay.DefaultDrawingAttributes.RasterOperation = rasterOp
  65.         End If
  66.     End Sub
  67.  
  68.     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
  69.         'Can be called prior to myInkOverlay being initialized, so check if that's the case
  70.         If myInkOverlay Is Nothing Then
  71.             Return
  72.         End If
  73.         SetAttributes()
  74.     End Sub
  75.  
  76.     'Sets the major attributes of the ink overlay (minus color, raster op, and some rare properties
  77.     Sub SetAttributes()
  78.         'Anti-aliasing
  79.         If antiAliasCheckbox.Checked = True Then
  80.             myInkOverlay.DefaultDrawingAttributes.AntiAliased = True
  81.         Else
  82.             myInkOverlay.DefaultDrawingAttributes.AntiAliased = False
  83.         End If
  84.  
  85.         'Pressure sensitivity
  86.         If pressureSensitiveCheckbox.Checked = True Then
  87.             myInkOverlay.DefaultDrawingAttributes.IgnorePressure = False
  88.         Else
  89.             myInkOverlay.DefaultDrawingAttributes.IgnorePressure = True
  90.         End If
  91.  
  92.         'Pen Tip
  93.         If penTipRectangle.Checked = True Then
  94.             myInkOverlay.DefaultDrawingAttributes.PenTip = PenTip.Rectangle
  95.         Else
  96.             myInkOverlay.DefaultDrawingAttributes.PenTip = PenTip.Ball
  97.         End If
  98.  
  99.         'Transparency
  100.         myInkOverlay.DefaultDrawingAttributes.Transparency = transparencyUpDown.Value
  101.  
  102.         'Height
  103.         myInkOverlay.DefaultDrawingAttributes.Height = heightUpDown.Value
  104.         'Width
  105.         myInkOverlay.DefaultDrawingAttributes.Width = widthUpDown.Value
  106.     End Sub
  107.  
  108.     'Handles "color" button
  109.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
  110.         'Create a standard dialog
  111.         Dim colorDialog As New ColorDialog()
  112.  
  113.         'Set color to current color
  114.         colorDialog.Color = myInkOverlay.DefaultDrawingAttributes.Color
  115.  
  116.         'Show it
  117.         If colorDialog.ShowDialog() = Windows.Forms.DialogResult.OK Then
  118.             'Set color to chosen
  119.             myInkOverlay.DefaultDrawingAttributes.Color = colorDialog.Color
  120.         End If
  121.     End Sub
  122.  
  123.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  124.         myInkOverlay.DefaultDrawingAttributes.Color = Color.Red
  125.     End Sub
  126.  
  127.     Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
  128.         myInkOverlay.DefaultDrawingAttributes.Color = Color.Black
  129.     End Sub
  130.  
  131.     Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
  132.         myInkOverlay.DefaultDrawingAttributes.Color = Color.Yellow
  133.     End Sub
  134.  
  135.     Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
  136.         myInkOverlay.DefaultDrawingAttributes.Color = Color.Orange
  137.     End Sub
  138.  
  139.     Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  140.         Try
  141.             Dim dir As String = Environ("USERPROFILE")
  142.             If (FileIO.FileSystem.DirectoryExists(dir & "\My Documents")) Then
  143.                 dir = dir & "\My Documents"
  144.             ElseIf (FileIO.FileSystem.DirectoryExists(dir & "\Documents")) Then
  145.                 dir = dir & "\Documents"
  146.             End If
  147.  
  148.             If (FileIO.FileSystem.DirectoryExists(dir & "\LifeSchool")) Then
  149.             Else
  150.                 FileIO.FileSystem.CreateDirectory(dir & "\LifeSchool")
  151.             End If
  152.             dir = dir & "\LifeSchool\"
  153.  
  154.             Dim file As String = dir & "temp.lss"
  155.             If (FileIO.FileSystem.FileExists(file)) Then
  156.                 FileSystem.Kill(file)
  157.             End If
  158.  
  159.             ScreenShotDemo.ScreenCapture.CaptureWindowToFile(Panel1.Handle, file, System.Drawing.Imaging.ImageFormat.Jpeg)
  160.  
  161.         Catch ex As Exception
  162.         End Try
  163.     End Sub
  164.  
  165.  
  166.  
  167.     Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
  168.         myInkOverlay.DefaultDrawingAttributes.Color = Color.Pink
  169.     End Sub
  170.  
  171.     Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
  172.         myInkOverlay.DefaultDrawingAttributes.Color = Color.Purple
  173.     End Sub
  174.  
  175.     Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
  176.         myInkOverlay.DefaultDrawingAttributes.Color = Color.Gray
  177.     End Sub
  178.  
  179.     Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
  180.         myInkOverlay.DefaultDrawingAttributes.Color = Color.Green
  181.     End Sub
  182.  
  183.     Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
  184.         myInkOverlay.DefaultDrawingAttributes.Color = Color.Lime
  185.     End Sub
  186.  
  187.     Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
  188.         myInkOverlay.DefaultDrawingAttributes.Color = Color.Blue
  189.     End Sub
  190.  
  191.     Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
  192.         myInkOverlay.DefaultDrawingAttributes.Color = Color.Maroon
  193.     End Sub
  194.  
  195.     Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
  196.         myInkOverlay.DefaultDrawingAttributes.Color = Color.Teal
  197.     End Sub
  198.  
  199.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  200.         If (FileIO.FileSystem.FileExists("Test.bmp")) Then
  201.             FileSystem.Kill("Test.bmp")
  202.         End If
  203.         ScreenShotDemo.ScreenCapture.CaptureWindowToFile(Panel1.Handle, "Test.bmp", System.Drawing.Imaging.ImageFormat.Bmp)
  204.         'My.Computer.Network.UploadFile("Test.bmp", "http://www.tomttb.com/school/api/board/upload.php")
  205.         'Our postvars
  206.         Dim strContents As String = ""
  207.         Dim objReader As IO.StreamReader
  208.         Try
  209.  
  210.             objReader = New IO.StreamReader("Test.bmp")
  211.             strContents = objReader.ReadToEnd()
  212.             objReader.Close()
  213.         Catch Ex As Exception
  214.         End Try
  215.         Dim buffer As Byte() = System.Text.Encoding.ASCII.GetBytes("uid=" & USER.Text & "&file=" & strContents)
  216.         'Initialisation, we use localhost, change if appliable
  217.         Dim WebReq As Net.HttpWebRequest = DirectCast(Net.WebRequest.Create("http://www.tomttb.com/school/api/board/upload.php"), Net.HttpWebRequest)
  218.         'Our method is post, otherwise the buffer (postvars) would be useless
  219.         WebReq.Method = "POST"
  220.         'We use form contentType, for the postvars.
  221.         WebReq.ContentType = "application/x-www-form-urlencoded"
  222.         'The length of the buffer (postvars) is used as contentlength.
  223.         WebReq.ContentLength = buffer.Length
  224.         'We open a stream for writing the postvars
  225.         Dim PostData As IO.Stream = WebReq.GetRequestStream()
  226.         'Now we write, and afterwards, we close. Closing is always important!
  227.         PostData.Write(buffer, 0, buffer.Length)
  228.         PostData.Close()
  229.         'Get the response handle, we have no true response yet!
  230.         Dim WebResp As Net.HttpWebResponse = DirectCast(WebReq.GetResponse(), Net.HttpWebResponse)
  231.         'Let's show some information about the response
  232.         MsgBox(WebResp.StatusCode)
  233.         MsgBox(WebResp.Server)
  234.  
  235.         'Now, we read the response (the string), and output it.
  236.         Dim Answer As IO.Stream = WebResp.GetResponseStream()
  237.         Dim _Answer As New IO.StreamReader(Answer)
  238.         MsgBox(_Answer.ReadToEnd())
  239.     End Sub
  240.  
  241.  
  242.     Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
  243.         If (myInkOverlay.Ink.Strokes.Count <> 0) Then
  244.             myInkOverlay.Ink.DeleteStroke(myInkOverlay.Ink.Strokes.Item(myInkOverlay.Ink.Strokes.Count - 1))
  245.         End If
  246.     End Sub
  247.  
  248.     Private Sub Panel1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
  249.         DeveloperField_HistoryId.Text = myInkOverlay.Ink.Strokes.Count
  250.     End Sub
  251. End Class
  252.  
Dec 23 '10 #1
0 1645

Sign in to post your reply or Sign up for a free account.

Similar topics

6
2305
by: Frank Wilson | last post by:
Tom, It sounds to me like ASP, not ASP.NET is handling the request for WebForm1.aspx. This is most likely an IIS config issue that may have been caused by order of installation or reinstallation, or possibly even something that happened in IIS before .NET was installed. Here is a way to prove or disprove my theory:
4
1274
by: Tim Wallace | last post by:
I have an ascx file in which I want to sometimes create an asp:button control based on a given value. Nothing I've tried has worked. How can I accomplish this task? Tim
11
1695
by: Sehboo | last post by:
Hi, I want to write a very very simple mail application which my father can use (maybe then I will be able to send and receive emails from him). This application will have a text box, where he will type a message, and a button. Once he presses this button the application will send an email to me (my email address will be hardcoded). I don't think that it can get any simpler. Problem is that how to send email from standalone machine...
4
4058
by: Nathan Pinno | last post by:
Hey all, Is there a way to create a button in either pygame or livewires, that is able to be clicked and when clicked sends a command to restart the program? Thanks, Nathan Pinno -- For great sites go to: http://www.the-web-surfers-store.com
4
1893
by: Adam - Regus | last post by:
I'm trying to create a button that prints 2 copies of a form. Using the wizard, I created a button that prints one automatically, using the following code: End Sub Private Sub CSR_BeforeUpdate(Cancel As Integer) End Sub Private Sub PRINTFORM_Click()
6
8247
by: Raji16 | last post by:
Hi, I am a new member. i am designing a simple judicial database system. however after creating tables i am a bit confused on setting the relationships between tables :confused: here is the link of a snapshot of my table design and i wud highly appreciate if anyone cud help me on building the table relationships. Link: http://www.geocities.com/raji_mll/Relationships.JPG The CaseID is the main primary key that links all my tables and we...
1
1694
by: Sinem | last post by:
Hello I am making a drawing application where I want the user to be able to draw straight lines (quite similar to the line tool in Flash). I want them to be able to draw these lines at any angle they want but they have to be straight and the lengths can only vary between 4 pixels long and 200 pixels long. (The weight of the lines I want to be 2 pixels). I would be ever so grateful if you could help me out on this, I have flash mx...
3
1829
by: =?Utf-8?B?ZGV2ZWxvcHNj?= | last post by:
Hi, can you guide me, which MS technologies are suitable to create drawing application (simple CAD application) on the web - to allow 2D/3D drawing on some canvas and use data stored on server (in some databases)? The resulting application can be either embedded on the web page or runnable directly from the web page - if it is possible with minimal depending installations on client computer. I know about Flash, Director or Java3D...
1
1481
by: bhavin12300 | last post by:
hi, i am creating one application called X from which i want to disable the button in Y application .(application y is not in my hand means i am not coder of that application) Y application have only one button on it.i just want to disable that button from X application. i think that it is possible by getting handle of Y application process but after getting handle of that i don't know what to do so that i can disable that button from X...
1
2803
by: starish | last post by:
Hello ... I have given code for undo in Sudoku which is: def get_entry(self, r, c): """Get the entry at row r and column c get_entry(int, int) -> char """
0
9603
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10644
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10379
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
6882
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4334
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3863
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.