VSTO 加载项自定义对话框响应
VSTO Addin Custom Dialog Box Responses
我有一个 Outlook 2013 插件,我想在其中显示一个带有 ShowDialog()
的对话框。我知道该怎么做,但我想问用户一个有 2 个答案的问题。意思是我想自定义按钮上的内容。我也不确定如何获得这样的自定义对话框结果。有人告诉我我还需要传递 Outlook window 句柄,我对应该使用什么方法来获取它感到有些困惑。
我需要帮助了解如何自定义对话框按钮(我认为这甚至可以在可视化设计器中使用 Form 完成)以及如何获取和测试自定义响应。比如我想问 "Do you want A or B?"
一个例子将不胜感激。
谢谢
如果我没有误解您的需要,为了做到这一点,您应该创建一个自定义表单,此自定义表单继承 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 中或通过单击组件的每个属性来执行此操作。
如你所见,我将 B 的 DialogResult 设置为 Ok(你可以根据需要更改它),因此你可以通过以下方式实现你想要的:
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
}
我有一个 Outlook 2013 插件,我想在其中显示一个带有 ShowDialog()
的对话框。我知道该怎么做,但我想问用户一个有 2 个答案的问题。意思是我想自定义按钮上的内容。我也不确定如何获得这样的自定义对话框结果。有人告诉我我还需要传递 Outlook window 句柄,我对应该使用什么方法来获取它感到有些困惑。
我需要帮助了解如何自定义对话框按钮(我认为这甚至可以在可视化设计器中使用 Form 完成)以及如何获取和测试自定义响应。比如我想问 "Do you want A or B?"
一个例子将不胜感激。
谢谢
如果我没有误解您的需要,为了做到这一点,您应该创建一个自定义表单,此自定义表单继承 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 中或通过单击组件的每个属性来执行此操作。 如你所见,我将 B 的 DialogResult 设置为 Ok(你可以根据需要更改它),因此你可以通过以下方式实现你想要的:
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
}