Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
StampFunction 1.0a - Form1.vb

Form1.vb

Caricato da: Mte90
Scarica il programma completo

  1. '--------------------------------------------------------------------
  2. 'Copyright (c) 2007-2009 Mte90, http://www.mte90.net
  3. 'All rights reserved.
  4. '
  5. 'Redistribution and use in source and binary forms, with or without
  6. 'modification, are permitted provided that the following conditions
  7. 'are met:
  8. '1. Redistributions of source code must retain the above copyright
  9. 'notice, this list of conditions and the following disclaimer.
  10. '2. Redistributions in binary form must reproduce the above copyright
  11. 'notice, this list of conditions and the following disclaimer in the
  12. 'documentation and/or other materials provided with the distribution.
  13. '3. The name of the author may not be used to endorse or promote products
  14. 'derived from this software without specific prior written permission.
  15. '
  16. 'THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  17. 'IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  18. 'OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  19. 'IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  20. 'INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  21. 'NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  22. 'DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  23. 'THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. '(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  25. 'THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. '--------------------------------------------------
  27. Imports System
  28. Imports System.Drawing
  29. Imports System.Drawing.Imaging
  30. Imports System.Xml.Serialization
  31. Imports System.IO
  32. Public Class Form1
  33.     Dim img As Image = DirectCast(Clipboard.GetDataObject().GetData(DataFormats.Bitmap), Image)
  34.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  35.         'questa è la img
  36.         If Clipboard.GetDataObject().GetData(DataFormats.Bitmap) Is Nothing Then
  37.         Else
  38.             PictureBox1.Image = Clipboard.GetDataObject().GetData(DataFormats.Bitmap)
  39.             Dim img As Image = DirectCast(Clipboard.GetDataObject().GetData(DataFormats.Bitmap), Image)
  40.             If img.Size.Height.ToString > PictureBox1.Size.Height.ToString Or img.Size.Width.ToString > PictureBox1.Size.Width.ToString Then
  41.                 PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
  42.                 info.Text = "L'immagine è stata rimpicciolita perchè più grande del contenitore immagine nell'anteprima."
  43.             ElseIf img.Size.Height.ToString < PictureBox1.Size.Height.ToString Or img.Size.Width.ToString < PictureBox1.Size.Width.ToString Then
  44.                 PictureBox1.SizeMode = PictureBoxSizeMode.Normal
  45.                 info.Text = "L'immagine è nelle misure originali perchè più piccola del contenitore immagine nell'anteprima."
  46.             End If
  47.         End If
  48.     End Sub
  49.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  50.         Dim numero As Integer
  51.         numero = 1
  52.         If path.Text = "" Then
  53.             MsgBox("Devi impostare un percorso!", MsgBoxStyle.Exclamation, "Errore")
  54.             Exit Sub
  55.         End If
  56.         If Not System.Windows.Forms.Clipboard.GetDataObject() Is Nothing Then
  57.             Dim oDataObj As IDataObject = System.Windows.Forms.Clipboard.GetDataObject()
  58.             If oDataObj.GetDataPresent(System.Windows.Forms.DataFormats.Bitmap) Then
  59.                 Dim oImgObj As System.Drawing.Image = oDataObj.GetData(DataFormats.Bitmap, True)
  60.                 For numero = 1 To 100
  61.                     If My.Computer.FileSystem.FileExists(path.Text & "\" & nome.Text & numero & ".gif") Then
  62.                         numero = numero + 1
  63.                         If ComboBox1.SelectedItem = "Gif" Then
  64.                             'To Save as Gif
  65.                             oImgObj.Save(path.Text & "\" & nome.Text & numero & ".gif", System.Drawing.Imaging.ImageFormat.Gif)
  66.                             info.Text = "L'immagine è stata salvata in formato Gif"
  67.                             Exit Sub
  68.                         End If
  69.                     End If
  70.                 Next numero
  71.                 For numero = 1 To 100
  72.                     If My.Computer.FileSystem.FileExists(path.Text & "\" & nome.Text & numero & ".bmp") Then
  73.                         numero = numero + 1
  74.                         If ComboBox1.SelectedItem = "Bmp" Then
  75.                             'To Save as bmp
  76.                             oImgObj.Save(path.Text & "\" & nome.Text & numero & ".bmp", System.Drawing.Imaging.ImageFormat.Bmp)
  77.                             info.Text = "L'immagine è stata salvata in formato Bmp"
  78.                             Exit Sub
  79.                         End If
  80.                     End If
  81.                 Next numero
  82.                 For numero = 1 To 100
  83.                     If My.Computer.FileSystem.FileExists(path.Text & "\" & nome.Text & numero & ".jpg") Then
  84.                         numero = numero + 1
  85.                         If ComboBox1.SelectedItem = "Jpg" Then
  86.                             'To Save as jpg
  87.                             oImgObj.Save(path.Text & "\" & nome.Text & numero & ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
  88.                             info.Text = "L'immagine è stata salvata in formato Jpg"
  89.                             Exit Sub
  90.                         End If
  91.                     End If
  92.                 Next numero
  93.                 For numero = 1 To 100
  94.                     If My.Computer.FileSystem.FileExists(path.Text & "\" & nome.Text & numero & ".png") Then
  95.                         numero = numero + 1
  96.                         If ComboBox1.SelectedItem = "Jpg" Then
  97.                             'To Save as jpg
  98.                             oImgObj.Save(path.Text & "\" & nome.Text & numero & ".png", System.Drawing.Imaging.ImageFormat.Jpeg)
  99.                             info.Text = "L'immagine è stata salvata in formato Png"
  100.                             Exit Sub
  101.                         End If
  102.                     End If
  103.                 Next numero
  104.                 For numero = 1 To 100
  105.                     If My.Computer.FileSystem.FileExists(path.Text & "\" & nome.Text & numero & ".tif") Then
  106.                         numero = numero + 1
  107.                         If ComboBox1.SelectedItem = "Tiff" Then
  108.                             'To Save as Tiff
  109.                             oImgObj.Save(path.Text & "\" & nome.Text & numero & ".tif", System.Drawing.Imaging.ImageFormat.Tiff)
  110.                             info.Text = "L'immagine è stata salvata in formato Tiff"
  111.                             Exit Sub
  112.                         End If
  113.                     End If
  114.                 Next numero
  115.                 For numero = 1 To 100
  116.                     If My.Computer.FileSystem.FileExists(path.Text & "\" & nome.Text & numero & ".ico") Then
  117.                         numero = numero + 1
  118.                         If ComboBox1.SelectedItem = "Ico" Then
  119.                             'To Save as ico
  120.                             oImgObj.Save(path.Text & "\" & nome.Text & numero & ".ico", System.Drawing.Imaging.ImageFormat.Icon)
  121.                             info.Text = "L'immagine è stata salvata in formato Ico"
  122.                             Exit Sub
  123.                         End If
  124.                     End If
  125.                 Next numero
  126.                 For numero = 1 To 100
  127.                     If My.Computer.FileSystem.FileExists(path.Text & "\" & nome.Text & numero & ".wmf") Then
  128.                         numero = numero + 1
  129.                         If ComboBox1.SelectedItem = "Wmf" Then
  130.                             'To Save as wmf
  131.                             oImgObj.Save(path.Text & "\" & nome.Text & numero & ".wmf", System.Drawing.Imaging.ImageFormat.Wmf)
  132.                             info.Text = "L'immagine è stata salvata in formato Wmf"
  133.                             Exit Sub
  134.                         End If
  135.                     End If
  136.                 Next numero
  137.             End If
  138.         End If
  139.     End Sub
  140.     Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
  141.         FolderBrowserDialog1.ShowDialog()
  142.         path.Text = FolderBrowserDialog1.SelectedPath
  143.     End Sub
  144.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  145.         If Clipboard.GetDataObject().GetData(DataFormats.Bitmap) Is Nothing Then
  146.         Else
  147.             PictureBox1.Image = Clipboard.GetDataObject().GetData(DataFormats.Bitmap)
  148.             Dim img As Image = DirectCast(Clipboard.GetDataObject().GetData(DataFormats.Bitmap), Image)
  149.             If img.Size.Height.ToString > PictureBox1.Size.Height.ToString Or img.Size.Width.ToString > PictureBox1.Size.Width.ToString Then
  150.                 PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
  151.                 info.Text = "L'immagine è stata rimpicciolita perchè più grande del contenitore immagine nell'anteprima."
  152.             ElseIf img.Size.Height.ToString < PictureBox1.Size.Height.ToString Or img.Size.Width.ToString < PictureBox1.Size.Width.ToString Then
  153.                 PictureBox1.SizeMode = PictureBoxSizeMode.Normal
  154.                 info.Text = "L'immagine è nelle misure originali perchè più piccola del contenitore immagine nell'anteprima."
  155.             End If
  156.             If path.Text = "" Then
  157.                 path.Text = My.Computer.FileSystem.SpecialDirectories.MyDocuments.ToString
  158.             End If
  159.             If My.Computer.FileSystem.FileExists((System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.Location) & "\opz.xml")) Then
  160.                 Dim deser As New XmlSerializer(GetType(customer))
  161.                 Dim streamrd As New StreamReader((System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.Location) & "\opz.xml"))
  162.                 Dim cust1 As customer
  163.                 cust1 = deser.Deserialize(streamrd)
  164.                 If cust1.formato = "Bmp" Then
  165.                     ComboBox1.SelectedItem = "Bmp"
  166.                 ElseIf cust1.formato = "Gif" Then
  167.                     ComboBox1.SelectedItem = "Gif"
  168.                 ElseIf cust1.formato = "Jpg" Then
  169.                     ComboBox1.SelectedItem = "Jpg"
  170.                 ElseIf cust1.formato = "Png" Then
  171.                     ComboBox1.SelectedItem = "Png"
  172.                 ElseIf cust1.formato = "Ico" Then
  173.                     ComboBox1.SelectedItem = "Ico"
  174.                 ElseIf cust1.formato = "Tiff" Then
  175.                     ComboBox1.SelectedItem = "Tiff"
  176.                 ElseIf cust1.formato = "Wmf" Then
  177.                     ComboBox1.SelectedItem = "Wmf"
  178.                 End If
  179.                 path.Text = cust1.percorso
  180.                 nome.Text = cust1.nome
  181.                 streamrd.Close()
  182.             Else
  183.                 Exit Sub
  184.             End If
  185.         End If
  186.     End Sub
  187.     Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
  188.         'Setta lo stile del bordo in modo che la finestra non venga visualizzata nella barra delle applicazioni
  189.         Me.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedToolWindow
  190.         'Nasconde la form
  191.         Me.Visible = False
  192.         'imposta la notifyicone del text
  193.         If Me.Visible = False AndAlso Me.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedToolWindow Then
  194.             NotifyIcon1.Text = "Stamp Function in StandBy"
  195.         End If
  196.     End Sub
  197.     Private Sub NotifyIcon1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick
  198.         'Ripristina il bordo normale
  199.         Me.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable
  200.         'Rende il form visibile
  201.         Me.Visible = True
  202.         'imposta la notifyicone del text
  203.         If Me.Visible = True AndAlso Me.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable Then
  204.             NotifyIcon1.Text = "Stamp Function in uso"
  205.         End If
  206.     End Sub
  207.     'Alt+Stamp
  208.     Private Sub Form1_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp
  209.         If e.KeyCode = Keys.Snapshot Then
  210.             If Me.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedToolWindow AndAlso Me.Visible = False Then
  211.                 If MsgBox("Nella memoria c'è una nuova immagine vuoi salvarla con Stamp Function?", MsgBoxStyle.OkCancel) = MsgBoxResult.Ok Then
  212.                     Me.Visible = True
  213.                     Me.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable
  214.                     PictureBox1.Image = Clipboard.GetDataObject().GetData(DataFormats.Bitmap)
  215.                     Dim img As Image = DirectCast(Clipboard.GetDataObject().GetData(DataFormats.Bitmap), Image)
  216.                     If img.Size.Height.ToString > PictureBox1.Size.Height.ToString Or img.Size.Width.ToString > PictureBox1.Size.Width.ToString Then
  217.                         PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
  218.                         info.Text = "L'immagine è stata rimpicciolita perchè più grande del contenitore immagine"
  219.                     ElseIf img.Size.Height.ToString < PictureBox1.Size.Height.ToString Or img.Size.Width.ToString < PictureBox1.Size.Width.ToString Then
  220.                         PictureBox1.SizeMode = PictureBoxSizeMode.Normal
  221.                         info.Text = "L'immagine è nelle misure originali perchè più piccola del contenitore immagine"
  222.                     End If
  223.                 Else
  224.                     Exit Sub
  225.                 End If
  226.             ElseIf Me.Visible = True AndAlso Me.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable Then
  227.                 If MsgBox("Nella memoria c'è una nuova immagine vuoi salvarla con Stamp Function?", MsgBoxStyle.OkCancel) = MsgBoxResult.Ok Then
  228.                     PictureBox1.Image = Clipboard.GetDataObject().GetData(DataFormats.Bitmap)
  229.                     Dim img As Image = DirectCast(Clipboard.GetDataObject().GetData(DataFormats.Bitmap), Image)
  230.                     If img.Size.Height.ToString > PictureBox1.Size.Height.ToString Or img.Size.Width.ToString > PictureBox1.Size.Width.ToString Then
  231.                         PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
  232.                         info.Text = "L'immagine è stata rimpicciolita perchè più grande del contenitore immagine"
  233.                     ElseIf img.Size.Height.ToString < PictureBox1.Size.Height.ToString Or img.Size.Width.ToString < PictureBox1.Size.Width.ToString Then
  234.                         PictureBox1.SizeMode = PictureBoxSizeMode.Normal
  235.                         info.Text = "L'immagine è nelle misure originali perchè più piccola del contenitore immagine"
  236.                     End If
  237.                 End If
  238.             End If
  239.         End If
  240.     End Sub
  241.     Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
  242.         If MsgBox("Vuoi che le opzioni: Formato,Percorso,Nome file vengano salvate per evitare il successivo reinserimento?", MsgBoxStyle.OkCancel) = MsgBoxResult.Ok Then
  243.             If path.Text = "" Then
  244.                 MsgBox("Devi selezionare un percorso!", MsgBoxStyle.Exclamation, "Errore")
  245.                 Exit Sub
  246.             ElseIf nome.Text = "" Then
  247.                 MsgBox("Devi selezionare un nome per il file!", MsgBoxStyle.Exclamation, "Errore")
  248.                 Exit Sub
  249.             End If
  250.             Dim srcustomer As New XmlSerializer(GetType(customer))
  251.             Dim cust As New customer(ComboBox1.SelectedItem, path.Text, nome.Text)
  252.             If My.Computer.FileSystem.FileExists((System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.Location) & "\opz.xml")) Then
  253.                 Dim writestream As New StreamWriter((System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.Location) & "\opz.xml"))
  254.                 srcustomer.Serialize(writestream, cust)
  255.             Else
  256.                 Dim file As System.IO.FileStream
  257.                 file = System.IO.File.Create((System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.Location) & "\opz.xml"))
  258.                 Dim writestream As New StreamWriter((System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.Location) & "\opz.xml"))
  259.                 srcustomer.Serialize(writestream, cust)
  260.                 writestream.Close()
  261.             End If
  262.         End If
  263.     End Sub
  264.     Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
  265.         Form2.Show()
  266.     End Sub
  267.  
  268.     Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
  269.         Form4.Show()
  270.     End Sub
  271. End Class
  272. Public Class customer
  273.     Public formato As String
  274.     Public percorso As String
  275.     Public nome As String
  276.     Public Sub New()
  277.     End Sub
  278.     Public Sub New(ByVal formato As String, ByVal percorso As String, ByVal nome As String)
  279.         Me.formato = formato
  280.         Me.percorso = percorso
  281.         Me.nome = nome
  282.     End Sub
  283. End Class