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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. ShowDialog Help

ShowDialog Help

Scheduled Pinned Locked Moved C#
questionhelp
4 Posts 4 Posters 1 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.
  • R Offline
    R Offline
    rikkemus
    wrote on last edited by
    #1

    Im making a window with 3 fields that needs to be filled out. Im using it as a modal window. 2 buttons for OK and Cancel. If the User presses OK, i want to inform him, he hasnt filled out all fields, if thats the case. And then keep the window open. The question is, how do i suppress the form from closing, when not every field is filled out. Thx in advance.

    W C RaviBeeR 3 Replies Last reply
    0
    • R rikkemus

      Im making a window with 3 fields that needs to be filled out. Im using it as a modal window. 2 buttons for OK and Cancel. If the User presses OK, i want to inform him, he hasnt filled out all fields, if thats the case. And then keep the window open. The question is, how do i suppress the form from closing, when not every field is filled out. Thx in advance.

      W Offline
      W Offline
      WillemM
      wrote on last edited by
      #2

      Don't fill in the DialogResult property of the Ok button, but set the dialogresult of the dialog using the eventhandler of the Ok button.

      private void okButton_Click(object sender,EventArgs e) {
      if(textField1.Text != "") {
      DialogResult = DialogResult.OK;
      }
      }

      Simple as that, if the textfield isn't filled, the dialogbox won't close. You can modify this to show a messagebox with the exact error. WM.
      What about weapons of mass-construction?

      1 Reply Last reply
      0
      • R rikkemus

        Im making a window with 3 fields that needs to be filled out. Im using it as a modal window. 2 buttons for OK and Cancel. If the User presses OK, i want to inform him, he hasnt filled out all fields, if thats the case. And then keep the window open. The question is, how do i suppress the form from closing, when not every field is filled out. Thx in advance.

        C Offline
        C Offline
        CWIZO
        wrote on last edited by
        #3

        Write a event hanlder for the Closing event. Inthere you check if the user has filled all the values and if he his not you set the Cancel property of the argument e to true: e.Cancel = true; -------------------------------------------------------- My development blog Q:What does the derived class in C# tell to it's parent? A:All your base are belong to us!

        1 Reply Last reply
        0
        • R rikkemus

          Im making a window with 3 fields that needs to be filled out. Im using it as a modal window. 2 buttons for OK and Cancel. If the User presses OK, i want to inform him, he hasnt filled out all fields, if thats the case. And then keep the window open. The question is, how do i suppress the form from closing, when not every field is filled out. Thx in advance.

          RaviBeeR Offline
          RaviBeeR Offline
          RaviBee
          wrote on last edited by
          #4

          Imho, this is best done using the ErrorProvider[^] component. It's a nice alternative to displaying a message box. /ravi My new year's resolution: 2048 x 1536 Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com

          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