Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. OpenDialogFile Issue

OpenDialogFile Issue

Scheduled Pinned Locked Moved C#
help
8 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PDTUM
    wrote on last edited by
    #1

    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

    F OriginalGriffO S 3 Replies Last reply
    0
    • P PDTUM

      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

      F Offline
      F Offline
      fjdiewornncalwe
      wrote on last edited by
      #2

      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.

      P 1 Reply Last reply
      0
      • P PDTUM

        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

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #3

        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

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        L B 2 Replies Last reply
        0
        • P PDTUM

          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

          S Offline
          S Offline
          SilimSayo
          wrote on last edited by
          #4

          How are you implementing your pages? are you using a tab control? On which pade is the rich text box?

          1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            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

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            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

            OriginalGriffO 1 Reply Last reply
            0
            • F fjdiewornncalwe

              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.

              P Offline
              P Offline
              PDTUM
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              • L Luc Pattyn

                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

                OriginalGriffO Offline
                OriginalGriffO Offline
                OriginalGriff
                wrote on last edited by
                #7

                :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 have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                1 Reply Last reply
                0
                • OriginalGriffO OriginalGriff

                  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

                  B Offline
                  B Offline
                  BillWoodruff
                  wrote on last edited by
                  #8

                  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

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups