0

I have an Add-in with ToolWindow (TW). The ToolWindow is a WindowFormControlLibrary (UC). On the UserControl there's a WebBrowser control (WB)

When AddIn is loaded, it initializes the ToolWindow, which means UserControl's InitializeComponent() event is called. I can call another event doNavigate(). And it navigates to the URL. and SHOW it in the WebBrowser control.

However, in the Add-in's Exec event, when I try to call the doNavigate() event. It load or at least does something, however, it does NOT display the page in the control.

    /*This file is UC.cs in WindowsFormControlLibrary Project */
    //Event is lanuched when the Add-in and tool window are loaded
    public UC() 
    {
        InitializeComponent();
        doNavigate("www.google.com");
    }

    public void doNavigaet(string url)
    {
        WB.Navigate(url);
        while (wBrowser.ReadyState != WebBrowserReadyState.Complete)
        {
            Application.DoEvents();
        }
    }

This is how I am calling the doNavigate() event from the Exec event of the Add-in

    /*This file is Connect.cs in the Addins Project.*/
    public void Exec(string CmdName, vsCommandExecOption ExecuteOption, ref object VariantIn, ref object VariantOut, ref bool Handled)
    {
        UC uc = new UC();
        UC.doNavigate("www.bing.com");            

        Handled = true;
        return;
    }

There's NO error, only the page (Bing) is not displayed in the web browser.

In the output window, I get: The thread '<No Name>' (0x502c) has exited with code 0 (0x0).

Could anyone please help me what could be the reason?

Thanks very much.

4

1 回答 1

0

toolWindow 创建为:

toolWin = toolWins.CreateToolWindow2(m_addIn, asmPath, ctlProgID, "MyToolWindow", guidStr, ref objTemp);

objTemp的值为null。原因是在“WindowsFormControlLibrary”项目中,在 AssemblyInfo.cs 文件中......

[assembly: ComVisible(false)] //Make it visible, put "true"!

...被设置为“假”。

在我将其更改为 后true,该变量objTemp现在包含UC为对象。最后,Exec方法变成了……

public void Exec(string CmdName, vsCommandExecOption ExecuteOption, ref object VariantIn, ref object VariantOut, ref bool Handled)
{
    UC uc = (UC)objTemp; //Casting object as UC
    uc.doNavigate("www.bing.com");            

    Handled = true;
    return;
}
于 2013-11-15T13:13:31.970 回答