带参数的VBScript CreateObject

时间:2012-08-01 15:06:02

标签: .net vbscript createobject

我正在尝试在VBS中打开Windows窗体并遇到一些困难: - (

此行正常(我认为):

Set frmPopup = CreateObject("System.Windows.Forms.Form")

但是第一行的以下内容失败:Microsoft VBScript运行时错误:ActiveX组件无法创建对象:'System.Drawing.Size'

    Set frmPopup.Size = CreateObject("System.Drawing.Size")
    frmPopup.Size.Width = cmintPSPFormWidth
    frmPopup.Size.Height = intPopupHeight

我猜那是因为System.Drawing.Size需要调用中指定的高度和宽度参数?

www谈到使用:

Set frmPopup.Size = new System.Drawing.Size(1,2)

但是这给了我:变量未定义:'系统'。

我已经从我的.NET 4安装文件夹中对System.Windows.Forms.dll和System.Drawing.dll进行了诽谤,但它仍然无效。有什么想法吗?

1 个答案:

答案 0 :(得分:2)

大小是一种方法,而不是ProgID。你可能需要这样的东西:

Set frmPopup = CreateObject("System.Windows.Forms.Form")
Set frmDrwg = CreateObject("System.Drawing")
frmDrwg.Size 1, 2

但是你必须记住,并非所有.NET对象都可以从VBS中正确实例化。