1. <small id='QdKJ5'></small><noframes id='QdKJ5'>

      • <bdo id='QdKJ5'></bdo><ul id='QdKJ5'></ul>
    2. <legend id='QdKJ5'><style id='QdKJ5'><dir id='QdKJ5'><q id='QdKJ5'></q></dir></style></legend>

      <i id='QdKJ5'><tr id='QdKJ5'><dt id='QdKJ5'><q id='QdKJ5'><span id='QdKJ5'><b id='QdKJ5'><form id='QdKJ5'><ins id='QdKJ5'></ins><ul id='QdKJ5'></ul><sub id='QdKJ5'></sub></form><legend id='QdKJ5'></legend><bdo id='QdKJ5'><pre id='QdKJ5'><center id='QdKJ5'></center></pre></bdo></b><th id='QdKJ5'></th></span></q></dt></tr></i><div id='QdKJ5'><tfoot id='QdKJ5'></tfoot><dl id='QdKJ5'><fieldset id='QdKJ5'></fieldset></dl></div>
      <tfoot id='QdKJ5'></tfoot>

      WinForms AcceptButton 不起作用?

      时间:2023-10-06

          <legend id='MO8uE'><style id='MO8uE'><dir id='MO8uE'><q id='MO8uE'></q></dir></style></legend>

            1. <i id='MO8uE'><tr id='MO8uE'><dt id='MO8uE'><q id='MO8uE'><span id='MO8uE'><b id='MO8uE'><form id='MO8uE'><ins id='MO8uE'></ins><ul id='MO8uE'></ul><sub id='MO8uE'></sub></form><legend id='MO8uE'></legend><bdo id='MO8uE'><pre id='MO8uE'><center id='MO8uE'></center></pre></bdo></b><th id='MO8uE'></th></span></q></dt></tr></i><div id='MO8uE'><tfoot id='MO8uE'></tfoot><dl id='MO8uE'><fieldset id='MO8uE'></fieldset></dl></div>
                <tbody id='MO8uE'></tbody>
              <tfoot id='MO8uE'></tfoot>
            2. <small id='MO8uE'></small><noframes id='MO8uE'>

              • <bdo id='MO8uE'></bdo><ul id='MO8uE'></ul>
                本文介绍了WinForms AcceptButton 不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                好吧,这让我很烦,我就是不知道出了什么问题......

                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");
                }
                

                第二个,即Form2,上面有两个按钮.我所做的只是将表单 AcceptButton 设置为一个,将 CancelButton 设置为另一个.在我看来,这就是完成这项工作所需要的一切.但是当我运行它时,我单击打开 Form2 的按钮.我现在可以单击设置为 CancelButton 的一组,然后出现Not OK"消息框.但是当我单击一组作为 AcceptButton 时,什么也没有发生?Form2 的 InitializeComponent 代码如下所示:

                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);
                }
                

                除了添加这两个按钮并设置 AcceptButton 和 CancelButton 之外,我什么也没做.为什么它不起作用?

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

                推荐答案

                仅仅设置AcceptButton/CancelButton是不够的.这只是告诉应该在 Enter/Esc 上调用哪个按钮.您必须设置按钮的 DialogResult 属性.

                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.

                这篇关于WinForms AcceptButton 不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:将非模态表单重新映射到现有应用程序 下一篇:.NET 中是否有等效的 Mac OS X 文档模式表?

                相关文章

                  <bdo id='GVLX2'></bdo><ul id='GVLX2'></ul>
                <legend id='GVLX2'><style id='GVLX2'><dir id='GVLX2'><q id='GVLX2'></q></dir></style></legend>

                <small id='GVLX2'></small><noframes id='GVLX2'>

                1. <i id='GVLX2'><tr id='GVLX2'><dt id='GVLX2'><q id='GVLX2'><span id='GVLX2'><b id='GVLX2'><form id='GVLX2'><ins id='GVLX2'></ins><ul id='GVLX2'></ul><sub id='GVLX2'></sub></form><legend id='GVLX2'></legend><bdo id='GVLX2'><pre id='GVLX2'><center id='GVLX2'></center></pre></bdo></b><th id='GVLX2'></th></span></q></dt></tr></i><div id='GVLX2'><tfoot id='GVLX2'></tfoot><dl id='GVLX2'><fieldset id='GVLX2'></fieldset></dl></div>

                2. <tfoot id='GVLX2'></tfoot>