Hey guys what I'm really trying to do is that i use same button to open image, convert it and save. Example on first click our button name is "select.." you click it and filedialog opens and you choose image, when you hit okay it changes name to convert, then u click convert and it saves it to your pc. But i cant get it working on second click. Can you check my code please?
Here it is:
`
Private CurrentFile As String
Private img As Image
Private Sub icbtn_Click(sender As Object, e As EventArgs) Handles icbtn.Click
If icbtn.Text = "Select.." Then
OpenFileDialog1.Title = "Open Image File"
OpenFileDialog1.Filter = "Bitmap Files|*.bmp" & "|Enhanced Windows MetaFile|*.emf" & "|Exchangeable Image File|*.exif" & "|Gif Files|*.gif|Icons|*.ico|JPEG Files|*.jpg" & "|PNG Files|*.png|TIFF Files|*.tif|Windows MetaFile|*.wmf"
OpenFileDialog1.DefaultExt = "bmp"
OpenFileDialog1.FilterIndex = 1
OpenFileDialog1.FileName = ""
OpenFileDialog1.ShowDialog()
If OpenFileDialog1.FileName = "" Then
Return
End If
img = Image.FromFile(OpenFileDialog1.FileName)
PictureBox1.Image = img
CurrentFile = OpenFileDialog1.FileName.ToString()
If PictureBox1.Image Is Nothing Then
icbtn.Text = "Select.."
ElseIf PictureBox1.Image Is img Then
icbtn.Text = "Convert!"
End If
ElseIf icbtn.Text = "Convert!" Then
If imgtypcb.SelectedItem = "Bitmap" Then
Dim newName As String = astb.Text + "\Pictures\" + System.IO.Path.GetFileNameWithoutExtension(CurrentFile)
newName = newName & ".bmp"
MsgBox(newName)
Try
Me.PictureBox1.Image.Save(newName, ImageFormat.Bmp)
Catch
MessageBox.Show("Failed to save image to bitmap.", "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
Return
End Try
MessageBox.Show("Image file saved to " & newName.ToString(), "Image Saved", MessageBoxButtons.OK, MessageBoxIcon.Information)
`