Groups | Blog | Home
all groups > c# > september 2004 >

c# : AxWebBrowser body background


Richard Steele
9/30/2004 11:38:53 PM
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





Robert Jordan
10/1/2004 1:07:08 AM
Hi Richard,

[quoted text, click to view]

Can you preview that HTML file with IE?

bye
Richard Steele
10/1/2004 8:12:59 AM
Yes i can, once it has been saved as html


[quoted text, click to view]

Richard Steele
10/1/2004 12:48:57 PM
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


[quoted text, click to view]

Richard Steele
10/1/2004 2:13:17 PM

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


[quoted text, click to view]

Robert Jordan
10/1/2004 2:51:51 PM
Hi Richard,

[quoted text, click to view]

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.

[quoted text, click to view]

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.

[quoted text, click to view]

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
Richard Steele
10/1/2004 3:13:19 PM
Robert

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

Thanks



[quoted text, click to view]

Robert Jordan
10/1/2004 3:34:36 PM
[quoted text, click to view]


[quoted text, click to view]

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
Richard Steele
10/1/2004 3:56:24 PM
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


[quoted text, click to view]

Robert Jordan
10/1/2004 4:37:26 PM
Hi Richard,

[quoted text, click to view]

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

bye
Robert Jordan
10/1/2004 5:20:40 PM
Hi Richard,

[quoted text, click to view]

It has, indeed. However, it will have the same flaw:

http://msdn2.microsoft.com/library/8bbc4s4h.aspx

When you set the DocumentText property, the WebBrowser
loads about:blank ;-)

bye
AddThis Social Bookmark Button