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 111921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:27:48+00:00 2026-05-11T02:27:48+00:00

Ok, this is bugging me, and I just can’t figure out what is wrong…

  • 0

Ok, this is bugging me, and I just can’t figure out what is wrong…

I have made two forms. First form just has a simple button on it, which opens the other as a dialog like so:

using (Form2 f = new Form2()) {     if (f.ShowDialog() != DialogResult.OK)         MessageBox.Show('Not OK');     else         MessageBox.Show('OK'); } 

The second, which is that Form2, has two buttons on it. All I have done is to set the forms AcceptButton to one, and CancelButton to the other. In my head this is all that should be needed to make this work. But when I run it, I click on the button which opens up Form2. I can now click on the one set as CancelButton, and I get the ‘Not OK’ message box. But when I click on the one set as AcceptButton, nothing happens? The InitializeComponent code of Form2 looks like this:

private void InitializeComponent() {     this.button1 = new System.Windows.Forms.Button();     this.button2 = new System.Windows.Forms.Button();     this.SuspendLayout();     //      // button1     //      this.button1.Location = new System.Drawing.Point(211, 13);     this.button1.Name = 'button1';     this.button1.Size = new System.Drawing.Size(75, 23);     this.button1.TabIndex = 0;     this.button1.Text = 'button1';     this.button1.UseVisualStyleBackColor = true;     //      // button2     //      this.button2.DialogResult = System.Windows.Forms.DialogResult.Cancel;     this.button2.Location = new System.Drawing.Point(130, 13);     this.button2.Name = 'button2';     this.button2.Size = new System.Drawing.Size(75, 23);     this.button2.TabIndex = 1;     this.button2.Text = 'button2';     this.button2.UseVisualStyleBackColor = true;     //      // Form2     //      this.AcceptButton = this.button1;     this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);     this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;     this.CancelButton = this.button2;     this.ClientSize = new System.Drawing.Size(298, 59);     this.Controls.Add(this.button2);     this.Controls.Add(this.button1);     this.Name = 'Form2';     this.Text = 'Form2';     this.Load += new System.EventHandler(this.Form2_Load);     this.ResumeLayout(false); } 

I have done nothing else than add those two buttons, and set the AcceptButton and CancelButton. Why doesn’t it work?

  • 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. 2026-05-11T02:27:48+00:00Added an answer on May 11, 2026 at 2:27 am

    Just setting the AcceptButton/CancelButton is not enough. This just tells which button should be invoked on Enter/Esc. You have to set the button’s DialogResult property.

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

Sidebar

Related Questions

This is really bugging me and I can't figure it out. I have a
OK, I'm having this very very simple error, but I can't figure it out
This is bugging me ... I have a simple HTML page that has a
This has been bugging me for more than two days now, so i thought
So this has been bugging me for some time and I can't seem to
This is a little general I know, but it's been bugging the hell out
Good morning, I've been up all night trying to figure this out on my
Maybe this is a stupid question but it's bugging me. I have a bi-directional
Why oh why is this so slow? I have made an isometric grid of
This is really bugging me, so I hope someone can help me a bit

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.