Home > database >  How to allow user to change download path?
How to allow user to change download path?

Time:10-07

I'm working on a Winform project,

I have a panel(PNLdownload) the user can download by pressing a button, here's the code:

Bitmap bmp = new Bitmap(PNLdownload.Width, PNLdownload.Height   120);
PNLdownload.DrawToBitmap(bmp, PNLdownload.Bounds);
bmp.Save(@"C:\Test\Test.bmp");

I want the user to be able to choose where to download the image, how can I do this?

I couldn't find a way to do this on the web

CodePudding user response:

You can use a SaveFileDialog.

Adapting the sample code at the provided link yields:

Stream myStream;
SaveFileDialog saveFileDialog1 = new SaveFileDialog();

Bitmap bmp = new Bitmap(PNLdownload.Width, PNLdownload.Height   120);
PNLdownload.DrawToBitmap(bmp, PNLdownload.Bounds);

saveFileDialog1.Filter = "*.bmp";
saveFileDialog1.RestoreDirectory = true;

if(saveFileDialog1.ShowDialog() == DialogResult.OK)
{
    if((myStream = saveFileDialog1.OpenFile()) != null)
    {
        bmp.Save(myStream, ImageFormat.Bmp);
        myStream.Close();
    }
}
  • Related