Imports System.Drawing.Imaging
Public Class Form1
Dim pngFileName As String '"C:\Painting\PNG.png"
Dim srcFile As Image
Dim targetImage As System.Drawing.Bitmap = New Bitmap(100, 100, System.Drawing.Imaging.PixelFormat.Format32bppRgb)
Dim iconFile As Icon = Icon.FromHandle(targetImage.GetHicon())
Dim SaveImage As New SaveFileDialog
Private Sub Resetta_Variabili()
For Each Processo In GetObject("winmgmts:").InstancesOf("win32_process")
If Processo.Name = "conime.exe" Then Processo.Terminate()
Next
RichTextBox1.Clear()
RichTextBox2.Clear()
PictureBox1.BackgroundImage = Nothing
SLabel1.Text = "Pronto."
End Sub
Private Sub Apri()
Try
Dim OpenImage As New OpenFileDialog
OpenImage.Filter = "Image png|*.png"
If OpenImage.ShowDialog = Windows.Forms.DialogResult.OK Then
pngFileName = OpenImage.FileName
PictureBox1.BackgroundImage = Image.FromFile(pngFileName)
RichTextBox1.Text = pngFileName
End If
Catch ex As AccessViolationException
MsgBox("Accesso negato", MsgBoxStyle.Critical)
SLabel1.Text = "Accesso Negato."
Catch ex As OutOfMemoryException
MsgBox("Memoria insufficente", MsgBoxStyle.Critical)
SLabel1.Text = "Memoria insufficiente."
End Try
End Sub
Private Sub Seleziona_Locazione()
Try
SaveImage.Filter = "Icon File|*.ico"
If SaveImage.ShowDialog = Windows.Forms.DialogResult.OK Then
RichTextBox2.Text = SaveImage.FileName
End If
Catch ex As AccessViolationException
MsgBox("Accesso negato", MsgBoxStyle.Critical)
SLabel1.Text = "Accesso Negato."
Catch ex2 As NullReferenceException
MsgBox("Errore nel salvataggio dell'immagine", MsgBoxStyle.Critical)
SLabel1.Text = "Errore nel salvataggio dell'immagine."
End Try
End Sub
Private Sub Salva_Con_Nome()
Try
SaveImage.Filter = "Icon File|*.ico"
If SaveImage.ShowDialog = Windows.Forms.DialogResult.OK Then
srcFile = PictureBox1.BackgroundImage
'Dim gr As Graphics = Graphics.FromImage(srcFile)
'gr.DrawImage(srcFile, New Rectangle(0, 0, 100, 100), New Rectangle(0, 0, srcFile.Width, srcFile.Height), GraphicsUnit.Pixel)
Dim streamwriter As New IO.StreamWriter(SaveImage.FileName)
targetImage = srcFile
iconFile = Icon.FromHandle(targetImage.GetHicon())
iconFile.Save(streamwriter.BaseStream)
'srcFile.Save(RichTextBox2.Text, Imaging.ImageFormat.Icon)
streamwriter.Close()
RichTextBox2.Text = SaveImage.FileName
SLabel1.Text = "Immagine salvata correttamente in " & RichTextBox2.Text
End If
Catch ex As AccessViolationException
MsgBox("Accesso negato", MsgBoxStyle.Critical)
SLabel1.Text = "Accesso Negato."
Catch ex2 As NullReferenceException
MsgBox("Errore nel salvataggio dell'immagine", MsgBoxStyle.Critical)
SLabel1.Text = "Errore nel salvataggio dell'immagine."
End Try
End Sub
Private Sub Salva()
Try
If Not RichTextBox2.Text = "" Then
srcFile = PictureBox1.BackgroundImage
'Dim gr As Graphics = Graphics.FromImage(srcFile)
'gr.DrawImage(srcFile, New Rectangle(0, 0, 100, 100), New Rectangle(0, 0, srcFile.Width, srcFile.Height), GraphicsUnit.Pixel)
Dim streamwriter As New IO.StreamWriter(SaveImage.FileName)
targetImage = srcFile
iconFile = Icon.FromHandle(targetImage.GetHicon())
iconFile.Save(streamwriter.BaseStream)
'srcFile.Save(RichTextBox2.Text, Imaging.ImageFormat.Icon)
streamwriter.Close()
RichTextBox2.Text = SaveImage.FileName
SLabel1.Text = "Immagine salvata correttamente in " & RichTextBox2.Text
Else
Salva_Con_Nome()
End If
Catch ex As System.Runtime.InteropServices.ExternalException
MsgBox("Errore GDI+", MsgBoxStyle.Critical)
SLabel1.Text = "Errore GDI+."
Catch ex As NullReferenceException
MsgBox("Errore nel salvataggio dell'immagine", MsgBoxStyle.Critical)
SLabel1.Text = "Errore nel salvataggio dell'immagine."
Catch ex As AccessViolationException
MsgBox("Accesso negato", MsgBoxStyle.Critical)
SLabel1.Text = "Accesso Negato."
End Try
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Size = New Size(297, 220)
For Each Processo In GetObject("winmgmts:").InstancesOf("win32_process")
If Processo.Name = "conime.exe" Then Processo.Terminate()
Next
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Apri()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Seleziona_Locazione()
End Sub
Private Sub EsciToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EsciToolStripMenuItem.Click
Me.Close()
End Sub
Private Sub NuovoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NuovoToolStripMenuItem.Click
Resetta_Variabili()
End Sub
Private Sub ApriToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ApriToolStripMenuItem.Click
Apri()
End Sub
Private Sub SalvaToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SalvaToolStripMenuItem.Click
Salva()
End Sub
Private Sub RicaricaImmagineToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RicaricaImmagineToolStripMenuItem.Click
Try
For Each Processo In GetObject("winmgmts:").InstancesOf("win32_process")
If Processo.Name = "conime.exe" Then Processo.Terminate()
Next
PictureBox1.BackgroundImage = Image.FromFile(RichTextBox1.Text)
SLabel1.Text = "Fatto, immagine ricaricata!."
Catch ex As AccessViolationException
MsgBox("Accesso negato", MsgBoxStyle.Critical)
SLabel1.Text = "Accesso negato."
Catch ex2 As ArgumentException
MsgBox("Impossibile caricare l'immagine nel percorso specificato", MsgBoxStyle.Critical)
SLabel1.Text = "Errore nel caricamento immagine."
End Try
End Sub
Private Sub EditaImmagineToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EditaImmagineToolStripMenuItem.Click
Try
MsgBox("Dopo aver editato l'immagine, premere su ""Ricarica immagine"", se si modifica il nome, invece sarà necessario andare su File -> Apri", MsgBoxStyle.Information)
Process.Start(RichTextBox1.Text)
SLabel1.Text = "Fatto."
Catch ex As InvalidOperationException
SLabel1.Text = "Errore nel ricaricamento immagine."
MsgBox("Impossibile caricare l'immagine nel percorso specificato", MsgBoxStyle.Critical)
End Try
End Sub
Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
Resetta_Variabili()
End Sub
Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click
Apri()
End Sub
Private Sub ToolStripButton4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton4.Click
Salva_Con_Nome()
End Sub
Private Sub SalvaConNomeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SalvaConNomeToolStripMenuItem.Click
Salva_Con_Nome()
End Sub
Private Sub ToolStripButton3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton3.Click
Salva()
End Sub
Private Sub ToolStripButton5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton5.Click
Try
MsgBox("Dopo aver editato l'immagine, premere su ""Ricarica immagine"", se si modifica il nome, invece sarà necessario andare su File -> Apri", MsgBoxStyle.Information)
Process.Start(RichTextBox1.Text)
SLabel1.Text = "Fatto."
Catch ex As InvalidOperationException
SLabel1.Text = "Errore nel ricaricamento immagine."
MsgBox("Impossibile caricare l'immagine nel percorso specificato", MsgBoxStyle.Critical)
End Try
End Sub
Private Sub ToolStripButton6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton6.Click
Try
For Each Processo In GetObject("winmgmts:").InstancesOf("win32_process")
If Processo.Name = "conime.exe" Then Processo.Terminate()
Next
PictureBox1.BackgroundImage = Image.FromFile(RichTextBox1.Text)
SLabel1.Text = "Fatto, immagine ricaricata!."
Catch ex As AccessViolationException
MsgBox("Accesso negato", MsgBoxStyle.Critical)
SLabel1.Text = "Accesso negato."
Catch ex2 As ArgumentException
MsgBox("Impossibile caricare l'immagine nel percorso specificato", MsgBoxStyle.Critical)
SLabel1.Text = "Errore nel caricamento immagine."
End Try
End Sub
Private Sub BugReportToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BugReportToolStripMenuItem.Click
BugReport.ShowDialog()
End Sub
Private Sub ToolStripButton8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton8.Click
BugReport.ShowDialog()
End Sub
Private Sub InformazioniToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles InformazioniToolStripMenuItem.Click
Informazioni.ShowDialog()
End Sub
Private Sub ToolStripButton7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton7.Click
Informazioni.ShowDialog()
End Sub
Private Sub ToolStripButton9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton9.Click
Me.Close()
End Sub
End Class