相关疑难解决方法(0)

144
推荐指数
6
解决办法
20万
查看次数

WinForms AcceptButton无法正常工作?

好吧,这让我烦恼,我只是想不通有什么问题......

我有两种形式.第一个表单只有一个简单的按钮,它打开另一个作为对话框,如下所示:

using (Form2 f = new Form2())
{
    if (f.ShowDialog() != DialogResult.OK)
        MessageBox.Show("Not OK");
    else
        MessageBox.Show("OK");
}
Run Code Online (Sandbox Code Playgroud)

第二个就是它Form2,上面有两个按钮.我所做的就是将表单AcceptButton设置为一个,将CancelButton设置为另一个.在我的脑海中,这是完成这项工作所需要的一切.但是当我运行它时,我点击打开Form2的按钮.我现在可以单击一个设置为CancelButton,然后我收到"Not OK"消息框.但当我点击一套作为AcceptButton时,没有任何反应?Form2的InitializeComponent代码如下所示:

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, …
Run Code Online (Sandbox Code Playgroud)

c# modal-dialog winforms

38
推荐指数
2
解决办法
3万
查看次数

如何在MessageBox中显示textBox控件?

知道如何在MessageBox中显示textBox控件.

我正在研究winforms projcet c#.

先感谢您.

.net c# winforms

11
推荐指数
2
解决办法
6万
查看次数

标签 统计

c# ×3

winforms ×2

.net ×1

modal-dialog ×1

vb.net ×1