Hello! What I am trying to do is to have 1 button in a form save both a bitmap and a text file in the same folder with just one click. So what I wanted it to do was to open a FolderBrowserDialog for the user to select a folder to save them in. I get the MsgBox saying "done" at the end though, but I see no created files.
Nothing is saved with this code:
vb Code:
Private Sub ButtonSave_Click(sender As System.Object, e As System.EventArgs) Handles ButtonSave.Click If MessageBox.Show("Would you like to save?", "Save As...", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then MessageBox.Show("Please choose a folder.", "Save As...", MessageBoxButtons.OK) If FolderBrowserDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then Dim Map As New Bitmap(PanelFullMapToSave.Width, PanelFullMapToSave.Height) PanelFullMapToSave.DrawToBitmap(Map, New Rectangle(0, 0, PanelFullMapToSave.Width, PanelFullMapToSave.Height)) Map.Save(FolderBrowserDialog1.SelectedPath & "bitmap.png", System.Drawing.Imaging.ImageFormat.Png) Dim SW As System.IO.StreamWriter = New System.IO.StreamWriter(FolderBrowserDialog1.SelectedPath & "data.txt") SW.WriteLine(Data) SW.Dispose() MsgBox("done") End If End If End Sub
HOWEVER I had previously used this code using a SaveFileDialog, and it worked (saved the bitmap in the location.) In this case I had only saved the bitmap.
vb Code:
Private Sub ButtonSave_Click(sender As System.Object, e As System.EventArgs) Handles ButtonSave.Click If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then Dim Map As New Bitmap(PanelFullMapToSave.Width, PanelFullMapToSave.Height) PanelFullMapToSave.DrawToBitmap(Map, New Rectangle(0, 0, PanelFullMapToSave.Width, PanelFullMapToSave.Height)) Map.Save(SaveFileDialog1.FileName, System.Drawing.Imaging.ImageFormat.Png) End If End Sub
Did I miss something in the first block of code? Thanks.




Reply With Quote
