473,414 Members | 1,948 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,414 software developers and data experts.

creating WebBrowser programmatically

Hi,

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();
  6.  
  7.             SuspendLayout();
  8.  
  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;
  21.  
  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);
  28.  
  29.             WindowState = FormWindowState.Maximized;
  30.         }
  31.  
Note as soon as I call Controls.Add(webBrowser) nothing appears. With that line removed I can see my form.

Thanks.
Nov 27 '08 #1
3 9410
nukefusion
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)
to
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
nukefusion
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

1
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...
2
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...
9
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...
1
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 ? ...
2
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...
8
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...
2
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...
1
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?
3
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)...
0
BarryA
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...
1
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.