Is there something like a WebBrowser class?

P

Peter Oliphant

It's not necessary, but it would be nice if there was a way I could easily
create something like a 'web browser form' or a 'display web page form' as
forms in my application (in a Panel would be even better!). Something that
allows browsing the internet within the window, or possibly just display a
web page that I choose (as the application author in code) to show without
the ability to browse. The later ability would allow me to change, say, the
help information without requiring a patch, just display the new info on the
webpage.

I'm programming using MS VS VC++ 2008 Express (Beta 2) /cli pure.

Thanx!

[==Peter==]
 
B

Ben Voigt [C++ MVP]

Peter Oliphant said:
It's not necessary, but it would be nice if there was a way I could easily
create something like a 'web browser form' or a 'display web page form' as
forms in my application (in a Panel would be even better!). Something that
allows browsing the internet within the window, or possibly just display a
web page that I choose (as the application author in code) to show without
the ability to browse. The later ability would allow me to change, say,
the help information without requiring a patch, just display the new info
on the webpage.

Did you even check the online help? There is
System::Windows::Forms::WebBrowser since .NET 2.0.
I'm programming using MS VS VC++ 2008 Express (Beta 2) /cli pure.

Thanx!

[==Peter==]
 
P

Peter Oliphant

Did you even check the online help? There is
System::Windows::Forms::WebBrowser since .NET 2.0.

Thanx!

I sure do, but I've learned not to trust it without a second opinion. I've
looked things up before only to find out it is dis-information, due to the
fact it is often the case there are two versions of the same class with the
same name just under different namespaces.

I recently had a bug that lasted for a week because I didn't know there are
more than TWO different Timer classes which look identical but don't work in
the same situations. In this case, don't try to manipulate Form controls
using a System::Timers::Timer, and don't try to launch Speech Recognition
using a System::Windows:Forms::Timer. You can see how just looking up one of
these Timers can lead you down the wrong path, and how does one even know to
look up DIFFERENT Timers to find what is needed, or know without
experimentation which ones work when and with what? MSDN is NOT a good
source to look things up the FIRST time one wants to use a new class (but
great once you know HOW TO use it, as a reference it is great, but a catalog
of car parts won't tell you how to build a car with them).

And yes, there is more than one WebBrowser class in different namespaces.
Plus, although I can see how it must haved looked to you, I got lucky with
the name. I didn't know that is what it is called. THAT is another problem
with MSDN, all you can do is HOPE you guess the same name that MS decided
upon. How did I know it wasn't going to be called Browser, or
InternetBrowser, or NetBrowser, or Webpage, or WebForm, or InternetForm, or
NetForm, or BrowserForm, etc.? And what if more than one of these exists,
and more than one class exists for each in different namespaces? How do I
know which one to use (the descriptions on the MSDN pages rarely tell you
when each is appropriate, its just a list of the components that make up the
class). And that's asuming the ability I want even exists, how do I even
know that? And if I find something that looks like the name implies it will
do what I want, I can't rely on it. For an example, try playing with
VScrollBar->ForeColor and VScrollBar->BackColor and see if they do what
you'd think they should do [hint - writing to them will CRASH the program in
many cases]... :)

And even when I do FIND a WebBrowser class, how do I know it is the BEST
class available for the task, espcially if it is a .NET 2.0 version? Too
many IF's not to ask someone's advice in a newsgroup like this, and it saves
a lot of time. I have answered similar questions in this newsgroup if
someone asks and I happen to know the answer, I even enjoy it!

So based on your answer, I'll look at the
System::Windows::Forms::WebBrowser. Until your answer, I couldn't be sure
what namespace to look in.

In short, trying to look something up without a human being giving advice is
prone to many days of working with the wrong class (and, like I said, this
has happened to me before)... : )

[==Peter==]

Ben Voigt said:
Peter Oliphant said:
It's not necessary, but it would be nice if there was a way I could
easily create something like a 'web browser form' or a 'display web page
form' as forms in my application (in a Panel would be even better!).
Something that allows browsing the internet within the window, or
possibly just display a web page that I choose (as the application author
in code) to show without the ability to browse. The later ability would
allow me to change, say, the help information without requiring a patch,
just display the new info on the webpage.

Did you even check the online help? There is
System::Windows::Forms::WebBrowser since .NET 2.0.
I'm programming using MS VS VC++ 2008 Express (Beta 2) /cli pure.

Thanx!

[==Peter==]
 
P

Peter Oliphant

OK, now I've read the WebBrowser class description (the one in the
System::Windows::Forms namespace). All is good, except when I tried to write
code and execute it I get a nasty error message, that has something to do
with 'Apartments' and 'Threads'. The description of WebBrowser says the
following:

"The WebBrowser class can only be used in threads set to single thread
apartment (STA) mode. To use this class, ensure that your Main method is
marked with the STAThreadAttribute attribute."

Ok, cool. So I went to the hyper-link 'STAThreadAttribute' and it went to
the STAThreadAttribute CLASS description, and IT says:

"In the .NET Framework version 2.0, new threads are initialized as
ApartmentState.MTA if their apartment state has not been set before they are
started. The main application thread is initialized to ApartmentState.MTA by
default. You can no longer set the main application thread to
ApartmentState.STA by setting the Thread.ApartmentState property on the
first line of code. Use the STAThreadAttribute instead."

However, in none of this description does it show HOW TO ' Use the
STAThreadAttribute instead'. The code examples that follow don't show how to
'use an attribute'. Since I've never used an attribute before, I'm at a
total loss. And I've never dealt with Threads before, and this seems to
assume I know all about the Thread class. And if the WebBrowser class has
been around since .NET 2.0, why do I need .NET 3.0 classes to make it work?

I'm guessing they changed how it works from 2.0 to 3.0. Yet another reason
just reading MSDN doesn't let you know if you're on the right track!

So, can someone please give me a code example of how to 'Use the
STAThreadAttribute' to set the main application thread to
ApartmentState.STA?

And more importantly, what the heck does this even mean (the MSDN page on
WebBrowser says nothing about how the differerent Apartment states are
different, what they are for, how many different types of them are there, or
even what the heck an Apartment state is). If this is important information
required to use the WebBrowser class shouldn't HOW TO USE IT be on the
WebBrowser class description page instead of an important note just saying
it's important?

Thanks in advance!

[==Peter==]


Peter Oliphant said:
Did you even check the online help? There is
System::Windows::Forms::WebBrowser since .NET 2.0.

Thanx!

I sure do, but I've learned not to trust it without a second opinion. I've
looked things up before only to find out it is dis-information, due to the
fact it is often the case there are two versions of the same class with
the same name just under different namespaces.

I recently had a bug that lasted for a week because I didn't know there
are more than TWO different Timer classes which look identical but don't
work in the same situations. In this case, don't try to manipulate Form
controls using a System::Timers::Timer, and don't try to launch Speech
Recognition using a System::Windows:Forms::Timer. You can see how just
looking up one of these Timers can lead you down the wrong path, and how
does one even know to look up DIFFERENT Timers to find what is needed, or
know without experimentation which ones work when and with what? MSDN is
NOT a good source to look things up the FIRST time one wants to use a new
class (but great once you know HOW TO use it, as a reference it is great,
but a catalog of car parts won't tell you how to build a car with them).

And yes, there is more than one WebBrowser class in different namespaces.
Plus, although I can see how it must haved looked to you, I got lucky with
the name. I didn't know that is what it is called. THAT is another problem
with MSDN, all you can do is HOPE you guess the same name that MS decided
upon. How did I know it wasn't going to be called Browser, or
InternetBrowser, or NetBrowser, or Webpage, or WebForm, or InternetForm,
or NetForm, or BrowserForm, etc.? And what if more than one of these
exists, and more than one class exists for each in different namespaces?
How do I know which one to use (the descriptions on the MSDN pages rarely
tell you when each is appropriate, its just a list of the components that
make up the class). And that's asuming the ability I want even exists, how
do I even know that? And if I find something that looks like the name
implies it will do what I want, I can't rely on it. For an example, try
playing with VScrollBar->ForeColor and VScrollBar->BackColor and see if
they do what you'd think they should do [hint - writing to them will CRASH
the program in many cases]... :)

And even when I do FIND a WebBrowser class, how do I know it is the BEST
class available for the task, espcially if it is a .NET 2.0 version? Too
many IF's not to ask someone's advice in a newsgroup like this, and it
saves a lot of time. I have answered similar questions in this newsgroup
if someone asks and I happen to know the answer, I even enjoy it!

So based on your answer, I'll look at the
System::Windows::Forms::WebBrowser. Until your answer, I couldn't be sure
what namespace to look in.

In short, trying to look something up without a human being giving advice
is prone to many days of working with the wrong class (and, like I said,
this has happened to me before)... : )

[==Peter==]

Ben Voigt said:
Peter Oliphant said:
It's not necessary, but it would be nice if there was a way I could
easily create something like a 'web browser form' or a 'display web page
form' as forms in my application (in a Panel would be even better!).
Something that allows browsing the internet within the window, or
possibly just display a web page that I choose (as the application
author in code) to show without the ability to browse. The later ability
would allow me to change, say, the help information without requiring a
patch, just display the new info on the webpage.

Did you even check the online help? There is
System::Windows::Forms::WebBrowser since .NET 2.0.
I'm programming using MS VS VC++ 2008 Express (Beta 2) /cli pure.

Thanx!

[==Peter==]
 
B

Ben Voigt [C++ MVP]

And even when I do FIND a WebBrowser class, how do I know it is the BEST
class available for the task, espcially if it is a .NET 2.0 version? Too
many IF's not to ask someone's advice in a newsgroup like this, and it
saves a lot of time. I have answered similar questions in this newsgroup
if someone asks and I happen to know the answer, I even enjoy it!

That is a very valid question. But most people reading "Is there something
like a WebBrowser class" don't realize that you actually wanted to know
about different options and the advantages of each.
 
B

Ben Voigt [C++ MVP]

Peter Oliphant said:
OK, now I've read the WebBrowser class description (the one in the
System::Windows::Forms namespace). All is good, except when I tried to
write code and execute it I get a nasty error message, that has something
to do with 'Apartments' and 'Threads'. The description of WebBrowser says
the following:

"The WebBrowser class can only be used in threads set to single thread
apartment (STA) mode. To use this class, ensure that your Main method is
marked with the STAThreadAttribute attribute."

Ok, cool. So I went to the hyper-link 'STAThreadAttribute' and it went to
the STAThreadAttribute CLASS description, and IT says:

"In the .NET Framework version 2.0, new threads are initialized as
ApartmentState.MTA if their apartment state has not been set before they
are started. The main application thread is initialized to
ApartmentState.MTA by default. You can no longer set the main application
thread to ApartmentState.STA by setting the Thread.ApartmentState property
on the first line of code. Use the STAThreadAttribute instead."

However, in none of this description does it show HOW TO ' Use the
STAThreadAttribute instead'. The code examples that follow don't show how
to 'use an attribute'. Since I've never used an attribute before, I'm at a
total loss. And I've never dealt with Threads before, and this seems to
assume I know all about the Thread class. And if the WebBrowser class has
been around since .NET 2.0, why do I need .NET 3.0 classes to make it
work?

I'm guessing they changed how it works from 2.0 to 3.0. Yet another reason
just reading MSDN doesn't let you know if you're on the right track!

So, can someone please give me a code example of how to 'Use the
STAThreadAttribute' to set the main application thread to
ApartmentState.STA?


I would guess:

public class MyApplication
{
public:
[STAThreadAttribute]
static void Main()
{
Application.Run(gcnew Form1())
}
}

But for C++ programs there is a better way:
http://msdn2.microsoft.com/en-us/library/s6bz81ya.aspx

And more importantly, what the heck does this even mean (the MSDN page on
WebBrowser says nothing about how the differerent Apartment states are
different, what they are for, how many different types of them are there,
or even what the heck an Apartment state is). If this is important
information required to use the WebBrowser class shouldn't HOW TO USE IT
be on the WebBrowser class description page instead of an important note
just saying it's important?

Thanks in advance!

[==Peter==]


Peter Oliphant said:
Did you even check the online help? There is
System::Windows::Forms::WebBrowser since .NET 2.0.

Thanx!

I sure do, but I've learned not to trust it without a second opinion.
I've looked things up before only to find out it is dis-information, due
to the fact it is often the case there are two versions of the same class
with the same name just under different namespaces.

I recently had a bug that lasted for a week because I didn't know there
are more than TWO different Timer classes which look identical but don't
work in the same situations. In this case, don't try to manipulate Form
controls using a System::Timers::Timer, and don't try to launch Speech
Recognition using a System::Windows:Forms::Timer. You can see how just
looking up one of these Timers can lead you down the wrong path, and how
does one even know to look up DIFFERENT Timers to find what is needed, or
know without experimentation which ones work when and with what? MSDN is
NOT a good source to look things up the FIRST time one wants to use a new
class (but great once you know HOW TO use it, as a reference it is great,
but a catalog of car parts won't tell you how to build a car with them).

And yes, there is more than one WebBrowser class in different namespaces.
Plus, although I can see how it must haved looked to you, I got lucky
with the name. I didn't know that is what it is called. THAT is another
problem with MSDN, all you can do is HOPE you guess the same name that MS
decided upon. How did I know it wasn't going to be called Browser, or
InternetBrowser, or NetBrowser, or Webpage, or WebForm, or InternetForm,
or NetForm, or BrowserForm, etc.? And what if more than one of these
exists, and more than one class exists for each in different namespaces?
How do I know which one to use (the descriptions on the MSDN pages rarely
tell you when each is appropriate, its just a list of the components that
make up the class). And that's asuming the ability I want even exists,
how do I even know that? And if I find something that looks like the name
implies it will do what I want, I can't rely on it. For an example, try
playing with VScrollBar->ForeColor and VScrollBar->BackColor and see if
they do what you'd think they should do [hint - writing to them will
CRASH the program in many cases]... :)

And even when I do FIND a WebBrowser class, how do I know it is the BEST
class available for the task, espcially if it is a .NET 2.0 version? Too
many IF's not to ask someone's advice in a newsgroup like this, and it
saves a lot of time. I have answered similar questions in this newsgroup
if someone asks and I happen to know the answer, I even enjoy it!

So based on your answer, I'll look at the
System::Windows::Forms::WebBrowser. Until your answer, I couldn't be sure
what namespace to look in.

In short, trying to look something up without a human being giving advice
is prone to many days of working with the wrong class (and, like I said,
this has happened to me before)... : )

[==Peter==]

Ben Voigt said:
It's not necessary, but it would be nice if there was a way I could
easily create something like a 'web browser form' or a 'display web
page form' as forms in my application (in a Panel would be even
better!). Something that allows browsing the internet within the
window, or possibly just display a web page that I choose (as the
application author in code) to show without the ability to browse. The
later ability would allow me to change, say, the help information
without requiring a patch, just display the new info on the webpage.

Did you even check the online help? There is
System::Windows::Forms::WebBrowser since .NET 2.0.


I'm programming using MS VS VC++ 2008 Express (Beta 2) /cli pure.

Thanx!

[==Peter==]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top