如何创建一个供 Excel AddIn 使用的对话框?

ole*_*der 1 c# excel user-interface vsto

我熟悉 Excel AddIns 的基础知识,但不知道如何设计、实现以及稍后显示内部对话框

请参阅此处带有图像的常设问题:

https://social.msdn.microsoft.com/Forums/en-US/935ebeae-1b88-4609-ba33-b0e522d2797f/how-to-create-a-dialog-for-use-by-an-excel-addin?论坛=exceldev

TIA

笔记:

(1)我的编程语言是C#

(2) 我更喜欢通过绘制对话框来设计对话框。

Eug*_*iev 5

您可以使用 MessageBox 类,例如:

const string message =
    "Are you sure that you would like to close the form?";
const string caption = "Form Closing";
var result = MessageBox.Show(message, caption,
                             MessageBoxButtons.YesNo,
                             MessageBoxIcon.Question);

// If the no button was pressed ... 
if (result == DialogResult.No)
{
    // cancel the closure of the form.
    e.Cancel = true;
}
Run Code Online (Sandbox Code Playgroud)

如果您想自定义对话框窗口,可以将新的Windows窗体添加到项目中,然后添加所需的控件。在代码中创建表单实例后,您可以使用 Show 或 ShowDialog 方法显示它。