【问题标题】:can't insert webbrowser inside panel in c#winapp无法在 c#winapp 的面板内插入 webbrowser
【发布时间】:2015-09-28 12:47:30
【问题描述】:

我无法将 webbrowser 控件添加到 winapp 中的面板,出现此错误“无法获取 'WebBrowser' 控件的窗口句柄。不支持无窗口 ActiveX 控件。”我也尝试使用 STAthread 来做到这一点

Thread uy = new Thread(me_p);
uy.SetApartmentState(ApartmentState.STA);
uy.Start();

private void me_p(object obj)
{
//throw new NotImplementedException();
this.p_bottom.Controls.Add(this.webBrowser2);         
}

【问题讨论】:

标签: c# webbrowser-control panel


【解决方案1】:

这样就可以正常使用了

private void InitializeComponent()
{
    this.panel1 = new System.Windows.Forms.Panel();
    this.webBrowser1 = new System.Windows.Forms.WebBrowser();
    this.panel1.SuspendLayout();
    this.SuspendLayout();
    // 
    // panel1
    // 
    this.panel1.Controls.Add(this.webBrowser1);
    this.panel1.Location = new System.Drawing.Point(47, 149);
    this.panel1.Name = "panel1";
    this.panel1.Size = new System.Drawing.Size(200, 100);
    this.panel1.TabIndex = 0;
    // 
    // webBrowser1
    // 
    this.webBrowser1.Dock = System.Windows.Forms.DockStyle.Fill;
    this.webBrowser1.Location = new System.Drawing.Point(0, 0);
    this.webBrowser1.MinimumSize = new System.Drawing.Size(20, 20);
    this.webBrowser1.Name = "webBrowser1";
    this.webBrowser1.Size = new System.Drawing.Size(200, 100);
    this.webBrowser1.TabIndex = 0;
    // 
    // Form1
    // 
    this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    this.ClientSize = new System.Drawing.Size(284, 261);
    this.Controls.Add(this.panel1);
    this.Name = "Form1";
    this.Text = "Form1";
    this.panel1.ResumeLayout(false);
    this.ResumeLayout(false);
}
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.WebBrowser webBrowser1;

您可以预先初始化浏览器,然后在您的线程中使用它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多