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)

`

There are many ways in which code does not work. What happens at each step? Does the text on the button change from "Select.." to "Convert!"? Does the conversion get done? Is the problem that you are not setting it back to "Select.." when the conversion is completed? Where exactly is the process breaking? You aren't showing us the entire block of code.

Yes. As @Reverend Jim said, Try to debug your application which helps you to solve most of your problem. If it is not solved, then post the error message and line of code which produces the message.

This is whole block of code. It changes button name to convert but when i click convert nothing happens

A whole block have code would not have a dangling If and a Sub with no End Sub. If you change your code to

ElseIf icbtn.Text = "Convert!" Then
    MsgBox("Convert!")

do you get the popup? Have you tried putting breakpoints and stepping through your code to see what is being executed and what the values are?

I have fixed problem. Just to find now solution how to make correct ico convert :)

Say, you are a jet pilot and during a flight your jet is badly malfunctioning.
Would you like the EJECT button on your ejector seat to mean something else, depending on some sort of condition?
A button that opens a file, should do just that, open a file. Same for the other actions. Use a menu or use separate buttons for every function.
For mouse hovering over a Button, PictureBox and changing the image,Click Here for a video tutorial.

Not actually I managed one button to have 2 functions which are working correct and perfectly ;)

Of course your code finally works! I'm happy with that.
Did certainly not mean to offend you, just was giving some advise.
Take it or leave it. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.