'--------------------------------------------------------------------
'Copyright (c) 2007-2009 Mte90, http://www.mte90.net
'All rights reserved.
'
'Redistribution and use in source and binary forms, with or without
'modification, are permitted provided that the following conditions
'are met:
'1. Redistributions of source code must retain the above copyright
'notice, this list of conditions and the following disclaimer.
'2. Redistributions in binary form must reproduce the above copyright
'notice, this list of conditions and the following disclaimer in the
'documentation and/or other materials provided with the distribution.
'3. The name of the author may not be used to endorse or promote products
'derived from this software without specific prior written permission.
'
'THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
'IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
'OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
'IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
'INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
'NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
'DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
'THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
'(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
'THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
'--------------------------------------------------
Imports System
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Xml.Serialization
Imports System.IO
Public Class Form1
Dim img As Image = DirectCast(Clipboard.GetDataObject().GetData(DataFormats.Bitmap), Image)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'questa è la img
If Clipboard.GetDataObject().GetData(DataFormats.Bitmap) Is Nothing Then
Else
PictureBox1.Image = Clipboard.GetDataObject().GetData(DataFormats.Bitmap)
Dim img As Image = DirectCast(Clipboard.GetDataObject().GetData(DataFormats.Bitmap), Image)
If img.Size.Height.ToString > PictureBox1.Size.Height.ToString Or img.Size.Width.ToString > PictureBox1.Size.Width.ToString Then
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
info.Text = "L'immagine è stata rimpicciolita perchè più grande del contenitore immagine nell'anteprima."
ElseIf img.Size.Height.ToString < PictureBox1.Size.Height.ToString Or img.Size.Width.ToString < PictureBox1.Size.Width.ToString Then
PictureBox1.SizeMode = PictureBoxSizeMode.Normal
info.Text = "L'immagine è nelle misure originali perchè più piccola del contenitore immagine nell'anteprima."
End If
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim numero As Integer
numero = 1
If path.Text = "" Then
MsgBox("Devi impostare un percorso!", MsgBoxStyle.Exclamation, "Errore")
Exit Sub
End If
If Not System.Windows.Forms.Clipboard.GetDataObject() Is Nothing Then
Dim oDataObj As IDataObject = System.Windows.Forms.Clipboard.GetDataObject()
If oDataObj.GetDataPresent(System.Windows.Forms.DataFormats.Bitmap) Then
Dim oImgObj As System.Drawing.Image = oDataObj.GetData(DataFormats.Bitmap, True)
For numero = 1 To 100
If My.Computer.FileSystem.FileExists(path.Text & "\" & nome.Text & numero & ".gif") Then
numero = numero + 1
If ComboBox1.SelectedItem = "Gif" Then
'To Save as Gif
oImgObj.Save(path.Text & "\" & nome.Text & numero & ".gif", System.Drawing.Imaging.ImageFormat.Gif)
info.Text = "L'immagine è stata salvata in formato Gif"
Exit Sub
End If
End If
Next numero
For numero = 1 To 100
If My.Computer.FileSystem.FileExists(path.Text & "\" & nome.Text & numero & ".bmp") Then
numero = numero + 1
If ComboBox1.SelectedItem = "Bmp" Then
'To Save as bmp
oImgObj.Save(path.Text & "\" & nome.Text & numero & ".bmp", System.Drawing.Imaging.ImageFormat.Bmp)
info.Text = "L'immagine è stata salvata in formato Bmp"
Exit Sub
End If
End If
Next numero
For numero = 1 To 100
If My.Computer.FileSystem.FileExists(path.Text & "\" & nome.Text & numero & ".jpg") Then
numero = numero + 1
If ComboBox1.SelectedItem = "Jpg" Then
'To Save as jpg
oImgObj.Save(path.Text & "\" & nome.Text & numero & ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
info.Text = "L'immagine è stata salvata in formato Jpg"
Exit Sub
End If
End If
Next numero
For numero = 1 To 100
If My.Computer.FileSystem.FileExists(path.Text & "\" & nome.Text & numero & ".png") Then
numero = numero + 1
If ComboBox1.SelectedItem = "Jpg" Then
'To Save as jpg
oImgObj.Save(path.Text & "\" & nome.Text & numero & ".png", System.Drawing.Imaging.ImageFormat.Jpeg)
info.Text = "L'immagine è stata salvata in formato Png"
Exit Sub
End If
End If
Next numero
For numero = 1 To 100
If My.Computer.FileSystem.FileExists(path.Text & "\" & nome.Text & numero & ".tif") Then
numero = numero + 1
If ComboBox1.SelectedItem = "Tiff" Then
'To Save as Tiff
oImgObj.Save(path.Text & "\" & nome.Text & numero & ".tif", System.Drawing.Imaging.ImageFormat.Tiff)
info.Text = "L'immagine è stata salvata in formato Tiff"
Exit Sub
End If
End If
Next numero
For numero = 1 To 100
If My.Computer.FileSystem.FileExists(path.Text & "\" & nome.Text & numero & ".ico") Then
numero = numero + 1
If ComboBox1.SelectedItem = "Ico" Then
'To Save as ico
oImgObj.Save(path.Text & "\" & nome.Text & numero & ".ico", System.Drawing.Imaging.ImageFormat.Icon)
info.Text = "L'immagine è stata salvata in formato Ico"
Exit Sub
End If
End If
Next numero
For numero = 1 To 100
If My.Computer.FileSystem.FileExists(path.Text & "\" & nome.Text & numero & ".wmf") Then
numero = numero + 1
If ComboBox1.SelectedItem = "Wmf" Then
'To Save as wmf
oImgObj.Save(path.Text & "\" & nome.Text & numero & ".wmf", System.Drawing.Imaging.ImageFormat.Wmf)
info.Text = "L'immagine è stata salvata in formato Wmf"
Exit Sub
End If
End If
Next numero
End If
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
FolderBrowserDialog1.ShowDialog()
path.Text = FolderBrowserDialog1.SelectedPath
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Clipboard.GetDataObject().GetData(DataFormats.Bitmap) Is Nothing Then
Else
PictureBox1.Image = Clipboard.GetDataObject().GetData(DataFormats.Bitmap)
Dim img As Image = DirectCast(Clipboard.GetDataObject().GetData(DataFormats.Bitmap), Image)
If img.Size.Height.ToString > PictureBox1.Size.Height.ToString Or img.Size.Width.ToString > PictureBox1.Size.Width.ToString Then
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
info.Text = "L'immagine è stata rimpicciolita perchè più grande del contenitore immagine nell'anteprima."
ElseIf img.Size.Height.ToString < PictureBox1.Size.Height.ToString Or img.Size.Width.ToString < PictureBox1.Size.Width.ToString Then
PictureBox1.SizeMode = PictureBoxSizeMode.Normal
info.Text = "L'immagine è nelle misure originali perchè più piccola del contenitore immagine nell'anteprima."
End If
If path.Text = "" Then
path.Text = My.Computer.FileSystem.SpecialDirectories.MyDocuments.ToString
End If
If My.Computer.FileSystem.FileExists((System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.Location) & "\opz.xml")) Then
Dim deser As New XmlSerializer(GetType(customer))
Dim streamrd As New StreamReader((System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.Location) & "\opz.xml"))
Dim cust1 As customer
cust1 = deser.Deserialize(streamrd)
If cust1.formato = "Bmp" Then
ComboBox1.SelectedItem = "Bmp"
ElseIf cust1.formato = "Gif" Then
ComboBox1.SelectedItem = "Gif"
ElseIf cust1.formato = "Jpg" Then
ComboBox1.SelectedItem = "Jpg"
ElseIf cust1.formato = "Png" Then
ComboBox1.SelectedItem = "Png"
ElseIf cust1.formato = "Ico" Then
ComboBox1.SelectedItem = "Ico"
ElseIf cust1.formato = "Tiff" Then
ComboBox1.SelectedItem = "Tiff"
ElseIf cust1.formato = "Wmf" Then
ComboBox1.SelectedItem = "Wmf"
End If
path.Text = cust1.percorso
nome.Text = cust1.nome
streamrd.Close()
Else
Exit Sub
End If
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
'Setta lo stile del bordo in modo che la finestra non venga visualizzata nella barra delle applicazioni
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedToolWindow
'Nasconde la form
Me.Visible = False
'imposta la notifyicone del text
If Me.Visible = False AndAlso Me.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedToolWindow Then
NotifyIcon1.Text = "Stamp Function in StandBy"
End If
End Sub
Private Sub NotifyIcon1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick
'Ripristina il bordo normale
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable
'Rende il form visibile
Me.Visible = True
'imposta la notifyicone del text
If Me.Visible = True AndAlso Me.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable Then
NotifyIcon1.Text = "Stamp Function in uso"
End If
End Sub
'Alt+Stamp
Private Sub Form1_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp
If e.KeyCode = Keys.Snapshot Then
If Me.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedToolWindow AndAlso Me.Visible = False Then
If MsgBox("Nella memoria c'è una nuova immagine vuoi salvarla con Stamp Function?", MsgBoxStyle.OkCancel) = MsgBoxResult.Ok Then
Me.Visible = True
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable
PictureBox1.Image = Clipboard.GetDataObject().GetData(DataFormats.Bitmap)
Dim img As Image = DirectCast(Clipboard.GetDataObject().GetData(DataFormats.Bitmap), Image)
If img.Size.Height.ToString > PictureBox1.Size.Height.ToString Or img.Size.Width.ToString > PictureBox1.Size.Width.ToString Then
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
info.Text = "L'immagine è stata rimpicciolita perchè più grande del contenitore immagine"
ElseIf img.Size.Height.ToString < PictureBox1.Size.Height.ToString Or img.Size.Width.ToString < PictureBox1.Size.Width.ToString Then
PictureBox1.SizeMode = PictureBoxSizeMode.Normal
info.Text = "L'immagine è nelle misure originali perchè più piccola del contenitore immagine"
End If
Else
Exit Sub
End If
ElseIf Me.Visible = True AndAlso Me.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable Then
If MsgBox("Nella memoria c'è una nuova immagine vuoi salvarla con Stamp Function?", MsgBoxStyle.OkCancel) = MsgBoxResult.Ok Then
PictureBox1.Image = Clipboard.GetDataObject().GetData(DataFormats.Bitmap)
Dim img As Image = DirectCast(Clipboard.GetDataObject().GetData(DataFormats.Bitmap), Image)
If img.Size.Height.ToString > PictureBox1.Size.Height.ToString Or img.Size.Width.ToString > PictureBox1.Size.Width.ToString Then
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
info.Text = "L'immagine è stata rimpicciolita perchè più grande del contenitore immagine"
ElseIf img.Size.Height.ToString < PictureBox1.Size.Height.ToString Or img.Size.Width.ToString < PictureBox1.Size.Width.ToString Then
PictureBox1.SizeMode = PictureBoxSizeMode.Normal
info.Text = "L'immagine è nelle misure originali perchè più piccola del contenitore immagine"
End If
End If
End If
End If
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
If MsgBox("Vuoi che le opzioni: Formato,Percorso,Nome file vengano salvate per evitare il successivo reinserimento?", MsgBoxStyle.OkCancel) = MsgBoxResult.Ok Then
If path.Text = "" Then
MsgBox("Devi selezionare un percorso!", MsgBoxStyle.Exclamation, "Errore")
Exit Sub
ElseIf nome.Text = "" Then
MsgBox("Devi selezionare un nome per il file!", MsgBoxStyle.Exclamation, "Errore")
Exit Sub
End If
Dim srcustomer As New XmlSerializer(GetType(customer))
Dim cust As New customer(ComboBox1.SelectedItem, path.Text, nome.Text)
If My.Computer.FileSystem.FileExists((System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.Location) & "\opz.xml")) Then
Dim writestream As New StreamWriter((System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.Location) & "\opz.xml"))
srcustomer.Serialize(writestream, cust)
Else
Dim file As System.
IO.
FileStream
file = System.
IO.
File.
Create((System.
IO.
Path.
GetDirectoryName(System.
Reflection.
Assembly.
GetExecutingAssembly.
Location) & "\opz.xml"))
Dim writestream As New StreamWriter((System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.Location) & "\opz.xml"))
srcustomer.Serialize(writestream, cust)
writestream.Close()
End If
End If
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Form2.Show()
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Form4.Show()
End Sub
End Class
Public Class customer
Public formato As String
Public percorso As String
Public nome As String
Public Sub New()
End Sub
Public Sub New(ByVal formato As String, ByVal percorso As String, ByVal nome As String)
Me.formato = formato
Me.percorso = percorso
Me.nome = nome
End Sub
End Class