473,372 Members | 1,078 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

creating WebBrowser programmatically


Background - I've create a windows application in VS and added a WebBrowser component and all works well.

I'm now trying to do this programmatically. My application now listens on a socket and when it receives a request it creates a new Form and adds a new WebBrowser.

The problem - All works well without the WebBrowser, the form is visible, but when I do "Controls.Add(webBrowser)" I see nothing, not even something in the windows bar.

Heres the constructor from my class that extends Form...
Expand|Select|Wrap|Line Numbers
  1.     public partial class Browser : Form
  2.     {
  3.         public Browser()
  4.         {
  5. //            InitializeComponent();
  7.             SuspendLayout();
  9.             webBrowser = new WebBrowser();
  10.             webBrowser.AllowWebBrowserDrop = false;
  11.             webBrowser.Dock = DockStyle.Fill;
  12.             webBrowser.IsWebBrowserContextMenuEnabled = false;
  13.             webBrowser.Location = new System.Drawing.Point(0, 0);
  14.             webBrowser.MinimumSize = new System.Drawing.Size(20, 20);
  15.             webBrowser.Name = "webBrowser";
  16.             webBrowser.ScrollBarsEnabled = false;
  17.             webBrowser.Size = new System.Drawing.Size(292, 273);
  18.             webBrowser.TabIndex = 0;
  19.             webBrowser.WebBrowserShortcutsEnabled = false;
  20.             webBrowser.Visible = true;
  22.             AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
  23.             AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  24.             ClientSize = new System.Drawing.Size(292, 273);
  25.             Controls.Add(webBrowser);
  26.             Name = "Browser";
  27.             ResumeLayout(true);
  29.             WindowState = FormWindowState.Maximized;
  30.         }
Note as soon as I call Controls.Add(webBrowser) nothing appears. With that line removed I can see my form.

Nov 27 '08 #1
3 9406
221 Expert 100+
I've just copied the code sample into a new form and it appears to run fine. I can see the web browser with no problems and it appears in the taskbar as it should. Maybe the problem is elsewhere in your code?
Nov 27 '08 #2
I've been trying to produce some cut down code to illustrate what i'm doing but can not get anything to work :(

So, i'd appreciate it if u could give me some pointers. Ultimately my app will be a console app or service. I started off with a windows app just to get to grips with Form's and WebBrowser. I've been able to produce a very simple windows app that creates a form with a WebBrowser in, easy!!

I tried to modify the Main method from
Expand|Select|Wrap|Line Numbers
  1. Application.Run(new Browser)
Expand|Select|Wrap|Line Numbers
  1. Thread t = new Thread((new Daemon).Start); t.start()
where Daemon listens for a socket connection then calls New Browser().

I believe it is the lack of call to Application.Run() that is at the heart of the problem.

Basically, how would I create a WebBrowser from a console application?
Nov 27 '08 #3
221 Expert 100+
I think your assumption that the missing Application.Run() statement is to blame would be correct. From what I remember of the top of my head, Application.Run starts a windows message pump for the form that is passed in as a parameter.
With your code example a message pump is not being started, just another thread. I would guess that this is your problem.
This is not something I've ever tried to do myself. Maybe you need to modify your daemon object to initiate an Application.Run for your browser form?
Nov 28 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Victor Hadianto | last post by:
Hi, Is it possible to programmatically add a history link in the web browser control without getting the WebBrowser control to visit a URL? -- Victor Hadianto...
by: Chris Bingham | last post by:
Hi everyone, Does anyone know how to fix the paper orientation depending on the paper size used when printing with the WebBrowser control please? What I've got is a HTML file, containing 1 big...
by: philip | last post by:
Is it possible, on a WebBrowser control, to intercept a HyperLink and react programmatically to this click ? That's my first question. In fact, I use the Webbrowser as a sort of report (I write...
by: JM | last post by:
I am using the WebBrowser control in .NET 2.0 Windows based application. I want to use the default IE security settings, privacy settings etc. Is there a way by which I can achieve this ? ...
by: Vadim Rapp | last post by:
Hello, I want to create a webbrowser object programmatically, navigate to a URL, and then analyze the document. I create the following code (simplified): Dim ie as new webbrowser...
by: Ludwig Wittgenstein | last post by:
Hi, all. How can i hook up an InternetExplorer object to a WebBrowser control that I have in my windows form. Basically what I want to do is automate the WebBrowser control via the...
by: M R | last post by:
i am writing an application (C#) that automates the process of loading a web page, login into a site and then simulates the navigation of the site. the program uses a winform with a webBrowser...
by: =?Utf-8?B?Q2FtZXJvbiBUYXlsb3I=?= | last post by:
Is there any way to programmatically purge the forward/back history of a .NET 2.0 embedded WebBrowser control?
by: Dom | last post by:
I have a prgram with a webBrowser control. The user can click on a Linked Reference and the webBrowser control shows that site. Sometimes the URL (not my program, but the URL I am browsing to)...
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.