OpenDialogFile Issue
-
Hello, I have an application that is composed of 2 forms. The first page launches the second page. On Page 2, I have a "Save As" button that launches a SaveFileDialog box, which works perfectly to save a file. However, whether I save or cancel, after it is done, the application closes Page 2 and restarts on Page 1. I want to application to simply return me to Page 2 where the Save As button is. I have tried several variations but have been unable to make it work that way. I am looking for a piece of code that will allow a new instruction when either Cancel or Save is selected from the SaveFileDialog box. I am including the save dialog code that I am using.
string savedFile = string.Empty;
// Displays a SaveFileDialog so the user can save the File SaveFileDialog saveFD = new SaveFileDialog(); saveFD.Filter = "Text Files|\*.txt|All Files|\*.\*"; saveFD.Title = "Save a Text File"; // If the user does not cancel, open Dialog Box to save the file. if (saveFD.ShowDialog() != DialogResult.Cancel) { savedFile = saveFD.FileName; richTextBoxSql.SaveFile(savedFile, RichTextBoxStreamType.PlainText); } else { //Code }
Any suggestions are gratefully appreciated. Thank You..Pat
-
Hello, I have an application that is composed of 2 forms. The first page launches the second page. On Page 2, I have a "Save As" button that launches a SaveFileDialog box, which works perfectly to save a file. However, whether I save or cancel, after it is done, the application closes Page 2 and restarts on Page 1. I want to application to simply return me to Page 2 where the Save As button is. I have tried several variations but have been unable to make it work that way. I am looking for a piece of code that will allow a new instruction when either Cancel or Save is selected from the SaveFileDialog box. I am including the save dialog code that I am using.
string savedFile = string.Empty;
// Displays a SaveFileDialog so the user can save the File SaveFileDialog saveFD = new SaveFileDialog(); saveFD.Filter = "Text Files|\*.txt|All Files|\*.\*"; saveFD.Title = "Save a Text File"; // If the user does not cancel, open Dialog Box to save the file. if (saveFD.ShowDialog() != DialogResult.Cancel) { savedFile = saveFD.FileName; richTextBoxSql.SaveFile(savedFile, RichTextBoxStreamType.PlainText); } else { //Code }
Any suggestions are gratefully appreciated. Thank You..Pat
The code you have provided is fine and will not cause the form that calls this code to close. You must have this save as button set as the Accept or Cancel button for the form, or the button click handler contains the formname.close call.
I wasn't, now I am, then I won't be anymore.
-
Hello, I have an application that is composed of 2 forms. The first page launches the second page. On Page 2, I have a "Save As" button that launches a SaveFileDialog box, which works perfectly to save a file. However, whether I save or cancel, after it is done, the application closes Page 2 and restarts on Page 1. I want to application to simply return me to Page 2 where the Save As button is. I have tried several variations but have been unable to make it work that way. I am looking for a piece of code that will allow a new instruction when either Cancel or Save is selected from the SaveFileDialog box. I am including the save dialog code that I am using.
string savedFile = string.Empty;
// Displays a SaveFileDialog so the user can save the File SaveFileDialog saveFD = new SaveFileDialog(); saveFD.Filter = "Text Files|\*.txt|All Files|\*.\*"; saveFD.Title = "Save a Text File"; // If the user does not cancel, open Dialog Box to save the file. if (saveFD.ShowDialog() != DialogResult.Cancel) { savedFile = saveFD.FileName; richTextBoxSql.SaveFile(savedFile, RichTextBoxStreamType.PlainText); } else { //Code }
Any suggestions are gratefully appreciated. Thank You..Pat
I tried pasting your code into a form, and displaying the form via both Show and ShowDialog. Even with an AcceptButton and a CancelButton defined, I could not make it close the form by closing the SaveFileDialog with the mouse on either button, or with the ENTER or ESC keys. In short - I cannot duplicate your problem from the information you have given. What are you doing that I am not? Have you tried removing code until it does work, then putting it back until it stops again?
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
-
Hello, I have an application that is composed of 2 forms. The first page launches the second page. On Page 2, I have a "Save As" button that launches a SaveFileDialog box, which works perfectly to save a file. However, whether I save or cancel, after it is done, the application closes Page 2 and restarts on Page 1. I want to application to simply return me to Page 2 where the Save As button is. I have tried several variations but have been unable to make it work that way. I am looking for a piece of code that will allow a new instruction when either Cancel or Save is selected from the SaveFileDialog box. I am including the save dialog code that I am using.
string savedFile = string.Empty;
// Displays a SaveFileDialog so the user can save the File SaveFileDialog saveFD = new SaveFileDialog(); saveFD.Filter = "Text Files|\*.txt|All Files|\*.\*"; saveFD.Title = "Save a Text File"; // If the user does not cancel, open Dialog Box to save the file. if (saveFD.ShowDialog() != DialogResult.Cancel) { savedFile = saveFD.FileName; richTextBoxSql.SaveFile(savedFile, RichTextBoxStreamType.PlainText); } else { //Code }
Any suggestions are gratefully appreciated. Thank You..Pat
-
I tried pasting your code into a form, and displaying the form via both Show and ShowDialog. Even with an AcceptButton and a CancelButton defined, I could not make it close the form by closing the SaveFileDialog with the mouse on either button, or with the ENTER or ESC keys. In short - I cannot duplicate your problem from the information you have given. What are you doing that I am not? Have you tried removing code until it does work, then putting it back until it stops again?
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
OriginalGriff wrote:
Have you tried ... putting it back until it stops again?
Now why would he want to do that? :laugh: Seriously, removing code to deal with a bug is fine, most bugs are in code you don't really need anyway; putting the bugs back in is a bit weird though.
Luc Pattyn [My Articles] Nil Volentibus Arduum
-
The code you have provided is fine and will not cause the form that calls this code to close. You must have this save as button set as the Accept or Cancel button for the form, or the button click handler contains the formname.close call.
I wasn't, now I am, then I won't be anymore.
Great Call Marcus....definitely a case of not being able to see the forest through the trees! I have this very poor habit of copying controls rather than making new one's, caused by my laziness when it comes to having to format. I may have done that with this button (or something else as foolish) and somehow managed to assign it the Cancel event. I gratefully gave you a fast five for this one. Best to all that replied. I truly do appreciate it. Luc...thank you for your input. Nice to see you replying to me again...Pat
-
OriginalGriff wrote:
Have you tried ... putting it back until it stops again?
Now why would he want to do that? :laugh: Seriously, removing code to deal with a bug is fine, most bugs are in code you don't really need anyway; putting the bugs back in is a bit weird though.
Luc Pattyn [My Articles] Nil Volentibus Arduum
:laugh: Take away in huge chunks: problem goes away. Put back smaller chunks: problem comes back. Your bug is now in a smaller bit of code, so repeat the process until you have a manageable code size that demonstrates the problem. I do like to be able to replicate bugs before I try to fix them... :-D
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
-
I tried pasting your code into a form, and displaying the form via both Show and ShowDialog. Even with an AcceptButton and a CancelButton defined, I could not make it close the form by closing the SaveFileDialog with the mouse on either button, or with the ENTER or ESC keys. In short - I cannot duplicate your problem from the information you have given. What are you doing that I am not? Have you tried removing code until it does work, then putting it back until it stops again?
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
Got my five on this one, which I think deserves posterity via some "idiom." My suggestion: "kill code until live: resurrect code until death." Actually it's a technique I use quite often to isolate bugs, along with trying to reproduce the bug "outside" the original context by creating a special test-case mini-app, or replacement class, or whatever. :) best, Bill
"Anyone who shows me my 'blind spots' gives me the gift of sight." ... a thought from the shallows of the deeply shallow mind of ... Bill