在VBScript中显示DLL的WinForm(C#)



我已经在DLL中创建了一个简单的表单,以显示/通过VBScript进行调用。

namespace Playground_DLL
{
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }
    private void button1_Click(object sender, EventArgs e)
    {
        this.DialogResult = System.Windows.Forms.DialogResult.OK;
    }
    public void ShowForm()
    {
        this.Show();
    }
    [ComVisible(true)]
    public void Hello()
    {
        MessageBox.Show("Hello");
        Application.Run(this);
    }
}

单击按钮后,我试图接收此表格的拨号。但是我正在努力使表格可见。DLL已注册,可以从VBScript中创建表单。但是在调用form.showdialog()方法后,脚本停止(或正在等待对话结束),但未显示表单。

仅当我调用(实验)hello()函数时,该表单是可见的。(但是,只有在调用application.lun之前要显示消息框。

我想念或做错了什么?

这是我的vbscript片段。

(整个脚本和形式并没有真正做任何事情。这只是为了学习/理解新概念)

Dim test
Set test = CreateObject("Playground_DLL.Form1")
test.topMost = True
test.Hello()
Msgbox(test.DialogResult)

Dim test
Set test = CreateObject("Playground_DLL.Form1")
test.topMost = True
Dim result
result = test.ShowDialog()
Msgbox(result)

您初始化窗口,但切勿显示它。您的测序和语法已关闭...

public void ShowForm()
{
    this.Show();
}
private void button1_Click(object sender, EventArgs e)
{
    Hello();     //Display your MessageBox based on the button click
    this.DialogResult = System.Windows.Forms.DialogResult.OK;
}
public void Hello()
{
    MessageBox.Show("Hello");
}
Dim test
Set test = CreateObject("Playground_DLL.Form1")     //This is where you initialize
test.topMost = true
//test.Hello()                                      //This is to display the message box - not Form1
test.ShowForm();                                    //This displays Form1

最新更新