开发者

Why c# winform is not shown when called from vbscript

开发者 https://www.devze.com 2023-03-28 21:21 出处:网络
i\'ve wrote a API in C# which will be used in vb6 & vbscript and assume my API details is as below:

i've wrote a API in C# which will be used in vb6 & vbscript and assume my API details is as below:

1. there is a form in the API but it is not exposed to COM

2. there is a method called ShowForm() with code "form1.Show()". This method ShowForm() is exposed to COM so that i can call this method from vb6/vbscript.

So, my problem is:

When i call ShowForm() method in vb6 under a button click event, the form created in C# API shows up but if i instantiate the same class and call the same method in vbscript, the form dont show up.

However, if i change the code in ShowForm(),

- from "form1.Show()" to "form1.ShowDialog()", it will show in both vb6/vbscript. But, it is showed as a modal form where what i want is modeless OR

- from "form1.Show()" to "Application.Run(form1)". It will shows up in vbscript but not in vb6 (it actually shows up in vb6, but it crash after i close the form in C#)

What can i do to make it works fine in vb6 and vbscript? Your advice is very much appreciated

PS: its not script syntax problem or COM problem. it should be something to do with form.show()/ShowDialog()/A开发者_开发技巧pplication.Run() or message loop thingy which is something i dont really understand

My code would be more or less something like this.

//C# code
public void ShowForm()
{
 m_frm.tempWebBrowser.Navigate("http://stackoverflow.com", "_self", Encoding.Default.GetBytes(""), "Content-Type: application/x-www-form-urlencoded");

 m_frm.FormBorderStyle = FormBorderStyle.Sizable;
 m_frm.ShowInTaskbar = true;
 m_frm.WindowState = FormWindowState.Maximized;
 m_frm.tempWebBrowser.Visible = true;

 m_frm.Show();     
}

//VB6 code, vbscript also using exactly the same code in the event
Private Sub Command1_Click()
 Dim tempClass
 Set tempClass = CreateObject("myClass.API")
 tempClass.ShowForm
End Sub


The form is not shown exactly because of what you suggested...there is no message pump running on the thread. If you are trying to fire-and-forget the C# window from VBScript, I suggest you launch it in a seperate process. It would have the same effect as you've described. If you instead were trying to launch it and wait for the user to interact with it (say you are prompting them for info) then showing to form modally is appropriate.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号