AxWebBrowser body background

R

Richard Steele

Can anyone help me

I am developing an application runs on a PC (client) only. For graphical
reasons it was decided that the content would be displayed in a Browser that
is embedded in a Windows Forms application (VS net 2003) c#

I have a Windows Form that uses a webbrowser (AxWebBrowser) )to display
html derived from internal classes that builds data from a database. The
HTML displays correctly. The HTML is built at runtime and the images are
stored locally on the c: drive

The issue i am having is displaying a background JPG using a body background
tag.
for example
<body background='C:\DOCUME~1\user\LOCALS~1\Temp\SalesBackGround.jpg'>

i have also tried

<body
background='file:///C:\DOCUME~1\user\LOCALS~1\Temp\SalesBackGround.jpg;

' leftmargin='0' marginheight='0' marginwidth='0'");

i have also tried copying the image to the executable's path

<body background='SalesBackGround.jpg'leftmargin='0' marginheight='0'
marginwidth='0'

Eveything after this statement displays corectly but the body background

if i copy the HTML after runtime to a new file (say in frontpage) and
preview the html it works perfectly

Can anybody help me



Thank You



Richard
 
R

Robert Jordan

Hi Richard,
<body background='SalesBackGround.jpg'leftmargin='0' marginheight='0'
marginwidth='0'

Eveything after this statement displays corectly but the body background

if i copy the HTML after runtime to a new file (say in frontpage) and
preview the html it works perfectly

Can you preview that HTML file with IE?

bye
Rob
 
R

Richard Steele

I have also gone through the DOM and accessed the body.background, this is
blank at runtime

I have managed to trick the WebBrowser to load the background by navigating
to

a html file that has the background image, then i load the dynamic html into
the DOM's innerHTML

my original plan though, was to have all my images as a embeded resource and
load the background

depending on the method at runtime ans simply load the HTML into the DOM's
innerHTML , i wanted to avoid navigating to a html file

as this loads the scrollbars and my application does not call for scroll
bars

Is this a bug or am i missing something
 
R

Robert Jordan

Hi Richard,
I have also gone through the DOM and accessed the body.background, this is
blank at runtime

I have managed to trick the WebBrowser to load the background by navigating
to

a html file that has the background image, then i load the dynamic html into
the DOM's innerHTML

This is not recommended. If you set the document like this,
the browser will put it in some strange security zone.
At least not in the local machine zone.

You should load the HTML from file beacuse it's the less cumbersome
solution.

You can embedd the HTML file as a .NET resource and
extract it at runtime into user's temp folder, for example.
my original plan though, was to have all my images as a embeded resource and
load the background

So how do you want to load those images into the browser?
Using the res:protocol? This doesn't work with .NET-resources.
It requires Win32-resources which you cannot embed using
Visual Studio.
depending on the method at runtime ans simply load the HTML into the DOM's
innerHTML , i wanted to avoid navigating to a html file

as this loads the scrollbars and my application does not call for scroll
bars

I don't understand what you mean with "does not call for scroll bars".
Do you want to prevent the scrollbars from apearing?
Use [body scroll="no"].

bye
Rob
 
R

Richard Steele

Robert

thanks for your help

so far i have managed to work out that the browser must have a preloaded
html file as i suppose it must initliaise itself

(sorry i am fairly new to c#, so i dont know the technical term)

The scroll bar question is mute, i have turned them of using the example you
gave me

once the browser has a preloaded file, i am free to change the backgound
image at will, this now works

are you suggesting that i never write the html directly to the innerHTML? or
should i create a HTML file on the fly

and navigate to that instead

Thanks

Richard


Robert Jordan said:
Hi Richard,
I have also gone through the DOM and accessed the body.background, this
is blank at runtime

I have managed to trick the WebBrowser to load the background by
navigating to

a html file that has the background image, then i load the dynamic html
into the DOM's innerHTML

This is not recommended. If you set the document like this,
the browser will put it in some strange security zone.
At least not in the local machine zone.

You should load the HTML from file beacuse it's the less cumbersome
solution.

You can embedd the HTML file as a .NET resource and
extract it at runtime into user's temp folder, for example.
my original plan though, was to have all my images as a embeded resource
and load the background

So how do you want to load those images into the browser?
Using the res:protocol? This doesn't work with .NET-resources.
It requires Win32-resources which you cannot embed using
Visual Studio.
depending on the method at runtime ans simply load the HTML into the
DOM's innerHTML , i wanted to avoid navigating to a html file

as this loads the scrollbars and my application does not call for scroll
bars

I don't understand what you mean with "does not call for scroll bars".
Do you want to prevent the scrollbars from apearing?
Use [body scroll="no"].

bye
Rob
 
R

Robert Jordan

Hi Richard Steele wrote:

are you suggesting that i never write the html directly to the innerHTML? or
should i create a HTML file on the fly

and navigate to that instead

The 2nd is recommended way. After you've loaded that local file
you can write directly to body.innerHTML.

BTW, you may wonder why this is required: if you don't
load a local file, the browser assumes the document
is in a special zone, the same zone as "about:blank" or so.
If you mix content from several zones (for example you
have some IFRAME, FRAME oder OBJECT tags) IE will show
a security warning or even worse: it will simply ignore the tags.

So just stick with that local file, even if it's not elegant.

bye
Rob
 
R

Richard Steele

Robert

will the browser show a warning even if it embedded into a Windows Form?

Thanks
 
R

Robert Jordan

Hi Richard,
Robert

will the browser show a warning even if it embedded into a Windows Form?

Yes. It depends on the user security setting. Very nasty.

bye
Rob
 
R

Richard Steele

Thanks Robert, u have been very helpful
i have created a html file with a nice error graphic, that will
be my initial page to navigate to
if anything fails then the user will see a nice graphic (error.htm)

BTW, i have managed to extract the images from my resource file
the issue i was also having was that the original image is a JPEG, when
the image was extracted it tripled in size (i presume it is a BMP)
i managed to find an example of code to convert it back
to a jpg, this now works and the background image gets replaced as per the
spec

do you happen to know if VS2005 will have a webbrowser control (managed
code)
Richard
 

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