Click here to Skip to main content
15,920,801 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Guys.
I have created a simple windows app in c# that enables users to convert images to jpg, png and bmp files.
This works well but my issue is that when ever i press the the "save button" the opens the save dialogue and asks the user to type in the name of the file as they would like it to be saved as ... but instead of the user to type the whole name ..e.g. "button.png" is there a way that i could code this so that the user could only type in "button" and the file automatically saves as "button.png" without the user actually typing in the the .PNG .. I hope this makes sense.
CODE:
i have 3 radio buttons to be selected by the user
radio button 1 = jpeg
radio button 2 = png
radio bbutton 3 = bmp

C#
private void button2_Click(object sender, EventArgs e)
{
    DialogResult saveimage = saveFileDialog1.ShowDialog();

    if (saveimage == DialogResult.OK)
    {

        if (radioButton1.Checked)
        {

            file.Save(saveFileDialog1.FileName, ImageFormat.Jpeg);
        }

        if (radioButton2.Checked)
        {

            file.Save(saveFileDialog1.FileName , ImageFormat.Png);

        }



        if (radioButton3.Checked)
        {

            file.Save(saveFileDialog1.FileName, ImageFormat.Bmp);
        }

    }
Posted
Comments
Sergey Alexandrovich Kryukov 19-Jun-13 19:41pm    
Not clear where the issue is. Do you want the user to type the name like "button"? Then the dialog does it. You should change dialog mask, no need in these radio button.
—SA
Christian Graus 19-Jun-13 19:43pm    
It's very clear, actually

If you pre select the type of image to save, and get the file save dialog to have a drop list of image types, or if you just have a button that is for each image type and let them type in the file name, you can either get the path with the extension from the save dialog, or append it yourself.
 
Share this answer
 
Hi
Check out the
C#
SaveFileDialog.AddExtension
property. For more details see the http://msdn.microsoft.com/en-us/library/system.windows.forms.filedialog.addextension.aspx[^]

Uroš
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900