2015-05-11 60 views
0

我有一個Outlook 2013插件,我想要顯示一個對話框ShowDialog()。我明白如何做到這一點,但我想用2個答案詢問用戶一個問題。含義我想定製按鈕上的內容。我也不確定如何獲得像這樣的自定義對話框結果。我被告知我需要傳遞Outlook窗口句柄,我對使用什麼方法來解決這個問題有些困惑。VSTO Addin自定義對話框響應

我需要幫助瞭解如何自定義我的對話框按鈕(我認爲它甚至可以在帶有窗體的可視化設計器中完成)以及如何獲取和測試自定義響應。例如,我想問「你想要A還是B?」

一個例子將不勝感激。

感謝

回答

1

如果我不誤解你的需要,爲了做到這一點,你應該創建一個定製的形式,這種形式的定製繼承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 
    } 
+0

完美謝謝。所以我只是使用正常的對話框結果確定其中的一個雅?這正是我需要的 – shenk

+0

@shenk,是的,你可以將DialogResult.Ok設置爲其中的一個,很高興它符合你的需求。 – Technovation