Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Visual Basic
Expertise: Intermediate
Nov 16, 1999

Display Proprietary Information in a WebBrowser Control Without an HTML File

When using the WebBrowser control in VB, you might want to present information without having that data accessible to the end user. In this case, you can simply insert the HTML code directly into the control. First create a blank document within the control, then set the HTML text directly-you don't need an external HTML file. This method also protects your HTML code; if users choose to View Source, all they see is "<HTML></HTML>":
 
Private Sub Form_Load()
	Dim strHTMLText As String
	' Create a blank document in the WebBrowser 
	' control
	WebBrowser1.Navigate2 "about:Blank"
	' Web browser may take awhile to process each 
	' command
	DoEvents
	On Error GoTo WaitAwhileLonger
	' Set the backcolor here
	WebBrowser1.Document.body.bgcolor = "#000000"
	' Set the HTML Text through code or from a 
	' Database
	strHTMLText = "<html>" & vbCrLf & _
		"<head>" & vbCrLf & _
		"<title>Common Controls Replacement" & _
		"Project</title>" & vbCrLf & _
		"</head>" & vbCrLf & "<body>" & _
		"<p align=""center"">_
		<font face=""Arial"" size=""5"" " & _
		"color=""#FFFFFF""><strong>_
		The Common Controls " & _
		"Replacement Project</strong></font></p>" _
		& "<p align=""center""> _
		<a href=""http://www.mvps.org/ccrp"">" & _
		"<img " & _
		"src=" _
		"http://www.mvps.org/ccrp/images/banner/" _
		& "ccrplogo.gif"" _
		alt=""Visit the CCRP's Internet Site." _
		" " & "border=""0""></a></p></body>" & _
		vbCrLf & "</html>"
	strHTMLText = strHTMLText & "<head>" & vbCrLf
	' Send the HTML Text to directly to the 
	' WebBrowser Control
	WebBrowser1.Document.body.innerhtml = _
		strHTMLText
Exit Sub

WaitAwhileLonger:
	Debug.Print Hex(Err.Number), Err.Description
	DoEvents
	Resume
End Sub
The WebBrowser control sometimes needs a little "encouragement" to fully finish the last task assigned before you can proceed with the next. That's the purpose of the error trap, which allows the WebBrowser a chance to catch its breath before attempting operations again.
Ramon Guerrero
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date