如果我不誤解你的需要,爲了做到這一點,你應該創建一個定製的形式,這種形式的定製繼承System.Windows.Forms.Form中。添加一個新的Windows窗體和設計它是這樣的:
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(70, 59);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(137, 17);
this.label1.TabIndex = 0;
this.label1.Text = "Do you want A or B?";
//
// button1
//
this.button1.Location = new System.Drawing.Point(35, 121);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 1;
this.button1.Text = "A";
this.button1.UseVisualStyleBackColor = true;
//
// button2
//
this.button2.DialogResult = System.Windows.Forms.DialogResult.OK;
this.button2.Location = new System.Drawing.Point(149, 121);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 2;
this.button2.Text = "B";
this.button2.UseVisualStyleBackColor = true;
您可以在CustomForm.Designer或通過單擊各個組件的屬性做到這一點。 你可以看到我設置的DialogResult B的爲好(你可以改變它,如果你想要的),這樣你就可以達到你想要的這個東西:
var frm = new CustomForm();//CustomForm is the name of your customized form
DialogResult res = frm.ShowDialog();
if (res == DialogResult.OK)
{
//do something, when user clicks on B
}
完美謝謝。所以我只是使用正常的對話框結果確定其中的一個雅?這正是我需要的 – shenk
@shenk,是的,你可以將DialogResult.Ok設置爲其中的一個,很高興它符合你的需求。 – Technovation