Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6920477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:09:08+00:00 2026-05-27T10:09:08+00:00

I have a windows form with multiple controls and OK and Cancel buttons. In

  • 0

I have a windows form with multiple controls and OK and Cancel buttons. In the Click event handler of OK button, it checks to see if there are errors on the form. I need the form to stay open if there are errors. But the code below is not working. If there are errors, it is closing the form and returning to the caller. And I have the below two lines to invoke and show the form.

PtForm paymentForm = new PtForm();
ptForm.ShowDialog();

private void btnOk_Click(object sender, EventArgs e)
    {
        this.ValidateChildren(ValidationConstraints.Visible);
        string ErrorString = GetValidationErrors();
        MessageBox.Show(ErrorString, "Errors");

        if (!string.IsNullOrEmpty(ErrorString))
        {
            return;
        }

//Processing

}

Thanks for any help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:09:09+00:00Added an answer on May 27, 2026 at 10:09 am

    There’s nothing in this code that will close the form. Therefore, the culprit must be outside this code.

    Did you set your OK button’s DialogResult property to DialogResult.OK? That would explain why the form is closing. AFAIK, if you set DialogResult on the button, that’s what happens — there’s no way to veto it in code.

    So in that case, you would need to go back to the designer and set the button’s DialogResult back to None. Then at the end of your btnOk_Click method, once you’ve validated all the input and decided that it’s safe to close the dialog, add a line that sets your Form’s DialogResult property to OK.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a windows form application. On the form there are three groupboxs. Each
I have a windows form simply like this: 1) a button when clicked will
I have windows forms application with multiple forms and controls in them. I want
I have a windows form with a primary tab control and multiple tabs (tabTest1,
I have a windows form that creates multiple console applications of the same program
I have a windows form app, and a class which is called Game. Let's
I have one windows form file that each time I open it in Visual
I have a windows form where in I open new threads for server communication.
i have a windows form that contains a bunch of textboxes. I need a
I have a windows form on the main thread and another thread that does

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.