473,396 Members | 2,010 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,396 software developers and data experts.

What's wrong with that code? Webbrowser control doesn't launch

Hello experts,
That's very very simple question but i wonder if you can help:

I have form1 and a button which brings user to form2 when button is
clicked, and i have a web-browser (.net 2.0 component) control placed
in form2 which is coded to run when form2 is loaded:

Form1 has only a button brings user to second form, form1 has that
code:

private void button1_Click(object sender, EventArgs e)
{
Form form2 = new Form();

form2.Show();
}
Form2 has that code:

private void Form2_Load(object sender, EventArgs e)
{
this.mybrowser.Navigate("http://www.google.com");
}
But then i run the program, when i go to form2 by clicking "button" in
form1, form 2 is shown empty as if there's no web-browser control
such. I'm beginner for C#, and there must be something missing.

Thanks...

Nov 7 '07 #1
9 2229
Did you attach the load handler routine to the event in the form2
constructor? You should have a line like this:

this.Load += new EventHandler(Form2_Load);

That's the only thing that I can think of at the moment.
"kimiraikkonen" wrote:
Hello experts,
That's very very simple question but i wonder if you can help:

I have form1 and a button which brings user to form2 when button is
clicked, and i have a web-browser (.net 2.0 component) control placed
in form2 which is coded to run when form2 is loaded:

Form1 has only a button brings user to second form, form1 has that
code:

private void button1_Click(object sender, EventArgs e)
{
Form form2 = new Form();

form2.Show();
}
Form2 has that code:

private void Form2_Load(object sender, EventArgs e)
{
this.mybrowser.Navigate("http://www.google.com");
}
But then i run the program, when i go to form2 by clicking "button" in
form1, form 2 is shown empty as if there's no web-browser control
such. I'm beginner for C#, and there must be something missing.

Thanks...

Nov 7 '07 #2
On Nov 8, 1:03 am, Family Tree Mike
<FamilyTreeM...@discussions.microsoft.comwrote:
Did you attach the load handler routine to the event in the form2
constructor? You should have a line like this:

this.Load += new EventHandler(Form2_Load);

That's the only thing that I can think of at the moment.

"kimiraikkonen" wrote:
Hello experts,
That's very very simple question but i wonder if you can help:
I have form1 and a button which brings user to form2 when button is
clicked, and i have a web-browser (.net 2.0 component) control placed
in form2 which is coded to run when form2 is loaded:
Form1 has only a button brings user to second form, form1 has that
code:
private void button1_Click(object sender, EventArgs e)
{
Form form2 = new Form();
form2.Show();
}
Form2 has that code:
private void Form2_Load(object sender, EventArgs e)
{
this.mybrowser.Navigate("http://www.google.com");
}
But then i run the program, when i go to form2 by clicking "button" in
form1, form 2 is shown empty as if there's no web-browser control
such. I'm beginner for C#, and there must be something missing.
Thanks...

put just before this.mybrowser.navigate("www.google.com")

Do you mean?

private void Form2_Load(object sender, EventArgs e)
{
this.Load += new EventHandler(Form2_Load);
this.mybrowser.Navigate("http://www.google.com");
}

If so, that didn't help.

Nov 8 '07 #3
Put the following line, after InitializeComponent()
this.Load += new EventHandler(Form2_Load);

You are trying to attach an event handler in the event, which will not
get raised.

HTH
Kalpesh


On Nov 7, 4:26 pm, kimiraikkonen <kimiraikkone...@gmail.comwrote:
On Nov 8, 1:03 am, Family Tree Mike

<FamilyTreeM...@discussions.microsoft.comwrote:
Did you attach the load handler routine to the event in the form2
constructor? You should have a line like this:
this.Load += new EventHandler(Form2_Load);
That's the only thing that I can think of at the moment.
"kimiraikkonen" wrote:
Hello experts,
That's very very simple question but i wonder if you can help:
I have form1 and a button which brings user to form2 when button is
clicked, and i have a web-browser (.net 2.0 component) control placed
in form2 which is coded to run when form2 is loaded:
Form1 has only a button brings user to second form, form1 has that
code:
private void button1_Click(object sender, EventArgs e)
{
Form form2 = new Form();
form2.Show();
}
Form2 has that code:
private void Form2_Load(object sender, EventArgs e)
{
this.mybrowser.Navigate("http://www.google.com");
}
But then i run the program, when i go to form2 by clicking "button" in
form1, form 2 is shown empty as if there's no web-browser control
such. I'm beginner for C#, and there must be something missing.
Thanks...

put just before this.mybrowser.navigate("www.google.com")

Do you mean?

private void Form2_Load(object sender, EventArgs e)
{
this.Load += new EventHandler(Form2_Load);
this.mybrowser.Navigate("http://www.google.com");
}

If so, that didn't help.

Nov 8 '07 #4
On 2007-11-07 17:01:00 -0800, Kalpesh <sh*********@gmail.comsaid:
Put the following line, after InitializeComponent()
this.Load += new EventHandler(Form2_Load);

You are trying to attach an event handler in the event, which will not
get raised.
And if it did get raised, each time the event got raised, the handler
would get added again, causing a geometrically increasing number of
handler executions for each raising of the event. :)

As far as subscribing the handler goes, IMHO in the case where the
handler is subscribed as part of initialization and never unsubscribed,
you might as well set the handler in the VS Designer rather than
explicitly writing the code to do so.

Pete

Nov 8 '07 #5
Peter,

I'm not following where you are suggesting the line goes. I have always put
it in my constructor after the call to InitializeComponent as Kalpesh stated.
The constructor is only called once.

Or... I just realized this. Are you addressing where Kimiraikkonen placed
here add handler code?
"Peter Duniho" wrote:
On 2007-11-07 17:01:00 -0800, Kalpesh <sh*********@gmail.comsaid:
Put the following line, after InitializeComponent()
this.Load += new EventHandler(Form2_Load);

You are trying to attach an event handler in the event, which will not
get raised.

And if it did get raised, each time the event got raised, the handler
would get added again, causing a geometrically increasing number of
handler executions for each raising of the event. :)

As far as subscribing the handler goes, IMHO in the case where the
handler is subscribed as part of initialization and never unsubscribed,
you might as well set the handler in the VS Designer rather than
explicitly writing the code to do so.

Pete

Nov 8 '07 #6
On 2007-11-07 19:16:00 -0800, Family Tree Mike
<Fa************@discussions.microsoft.comsaid:
Peter,

I'm not following where you are suggesting the line goes. I have always put
it in my constructor after the call to InitializeComponent as Kalpesh stated.
The constructor is only called once.

Or... I just realized this. Are you addressing where Kimiraikkonen placed
here add handler code?
My post addresses two different issues:

1) The consequence of the improperly placed statement subscribing the
handler, as seen in kimiraikkonen's post.

2) The question of whether one should write code to subscribe a
handler at all. For a situation such as this one, the VS Designer
provides a very easy way to auto-generate the needed code, so why write
it oneself at all?

Nothing in my post was suggesting a specific location for the line
being suggested, other than to agree with Kalpesh's post saying that
the OP has it in the wrong place. My preference is to avoid the
question of where the line goes altogether, by having the Designer
write the line of code instead.

Pete

Nov 8 '07 #7
Thanks, now I understand!

"Peter Duniho" wrote:
On 2007-11-07 19:16:00 -0800, Family Tree Mike
<Fa************@discussions.microsoft.comsaid:
Peter,

I'm not following where you are suggesting the line goes. I have always put
it in my constructor after the call to InitializeComponent as Kalpesh stated.
The constructor is only called once.

Or... I just realized this. Are you addressing where Kimiraikkonen placed
here add handler code?

My post addresses two different issues:

1) The consequence of the improperly placed statement subscribing the
handler, as seen in kimiraikkonen's post.

2) The question of whether one should write code to subscribe a
handler at all. For a situation such as this one, the VS Designer
provides a very easy way to auto-generate the needed code, so why write
it oneself at all?

Nothing in my post was suggesting a specific location for the line
being suggested, other than to agree with Kalpesh's post saying that
the OP has it in the wrong place. My preference is to avoid the
question of where the line goes altogether, by having the Designer
write the line of code instead.

Pete

Nov 8 '07 #8
Hi,
Read all the posts but that didn't work neither:

public Form2()
{
InitializeComponent();
this.Load += new EventHandler(Form2_Load);
}

private void Form2_Load(object sender, EventArgs e)
{

this.mybrowser.Navigate("http://www.google.com");
}
It's not required to use that code if there's no form1 / even didn't
work if form1 exists also.
this.Load += new EventHandler(Form2_Load);

if i form2 is unique / only and starter form of the project, i mean,
if i delete form1, form2's webbrowser function will work but
couldn't understand why the problem occurs when you jump from form1 to
form2.

Nov 8 '07 #9
On 2007-11-08 11:55:55 -0800, kimiraikkonen <ki*************@gmail.comsaid:
[...]
if i form2 is unique / only and starter form of the project, i mean,
if i delete form1, form2's webbrowser function will work but
couldn't understand why the problem occurs when you jump from form1 to
form2.
You know, the bottom line here is that you have not posted nearly a
good enough problem description for anyone to really answer your
question.

You should post a concise-but-complete sample of code that reliably
demonstrates your problem. You should also be very specific about what
user steps to take when running the code, what the code actually does,
and what you expect it to do instead.

Pete

Nov 8 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jim Hubbard | last post by:
According to Visual Studio 2003 Help files "In Internet Explorer 6 or later, the BeforeNavigate2 event fires only before the first navigation made in code. It does not fire when a user clicks a...
9
by: Josh Mayfield | last post by:
Note: There is considerable background detail here, but I do have three questions, which are clearly marked and appear right before the sample code. I have a legitimate need to launch an EXE...
3
by: Jim | last post by:
I'd like to hook events (like when a user clicks or right-clicks on a link in a web page) to launch a download manager or to open a new window for the link, but I am finding it difficult to find...
0
by: Vin | last post by:
The .Net 2.0's webbrowser is neat and pretty. But I am not able to capture Key events when the focus is on the webbrowser control in my winform. Options tried. 1. Wrote a class which extends this...
8
by: Prosperz | last post by:
Hi, I would like to make thumbnails of web page by capture content of a WebBrowser. By example, capture http://www.google.com. I used WebBrowser control with Framework 2.0. I try this : ...
2
by: jasonhartsoe | last post by:
I'm using Visual Studio 2005 Team Edition....using visual basic. I'm trying to use the webbrowser control. In the webbrowser control I have it got to a page where there is a form. It waits for...
1
by: L. Chernov | last post by:
Hello, I am trying to work with .Net 2005 WebBrowser object, and put it on a "Windows control library" (embedded in a user control class) and then I am executing it from an ASP.Net webform(with...
11
by: Anil Gupte | last post by:
....and how do I insert one into my form? I used in VB 6.0 last, but cannot figure out where it is in .Net Thanx, -- Anil Gupte www.keeninc.net www.icinema.com
0
by: BartlebyScrivener | last post by:
Hello, On Debian Etch, when I use the webbrowser.open module to launch firefox with a url, it opens UNDER gnome terminal in the background. If I just launch firefox from the commandline, it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
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
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...
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...

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.