Visual Basic Development Bookmark and Share   
 Home > Visual Basic Language > Display HTML in form
 

Display HTML in form

Hi! I'm new here and new to VB. I hope this is an easy question with an easy solution.
I am developing a text script "Format" program for work for me to use in our CRM program.

I have one texbox which gets populated with a textfile (containing HTML tags) via Option buttons. I want to be able to edit the HTML template in teh textbox and show the edit updates in a ObjectBrowser.
So I do not want to 'WebBrowser1.navigate' anywhere, I just want to take the text contents of Textbox1 and dispay them as HTML on Webbrowser1.

Am I constructing this right with the Browser obj or is there a better way?
JustinP  Sunday, December 24, 2006 8:14 PM

can you define by what you mean by "as a web html format"?

do you mean whatever you typed into textbox1 you want to show in the webbrowser control?

if you mean show the contents of textbox1 as a web doc you can. you need to place they html body tags around the textbox1 text then show it:

Me.theWebBrowserControl.DocumentText = "<body>" & Me.textBox1.Text & "</body>"

'Me.theWebBrowserControl.Refresh(WebBrowserRefreshOption.Completely) 'C# has this option for some reason

Me.theWebBrowserControl.Update()

 

 

ahmedilyas  Monday, December 25, 2006 3:06 PM

Public Class Form1

Const Header As String = "<html><head></head><body>"

Const closee As String = "</body></html>"

Private Sub cbGo_Click(ByVal sender As Object, _

ByVal e As System.EventArgs) Handles cbGo.Click

WB.DocumentText = Header + TextBox1.Text + closee

End Sub

End Class

ReneeC  Tuesday, December 26, 2006 1:13 AM

you should use the .NET classes to open/read files rather than the old methods of VB

alternatively you could just navigate to the path in the webbrowser control as you almost have done..

Me.WebBrowser1.Navigate(Application.StartupPath & "\previewcd.html")

not sure if this is intentional from your code but you are doing nothing in the Textbox apart from reading the file and placing the text in it. Unless you are, as stated earlier, wanting that to be your "editor" :-)

Dim theReader as new System.IO.StreamReader(Application.StartupPath & "\previewcd.html")

Me.Text1.Text = theReader.ReadToEnd()

theReader.Close()

this is the correct .NET way of reading files

ahmedilyas  Tuesday, December 26, 2006 6:09 PM

 

Hi,

Try the "TRY IT" editor at http://www.w3schools.com/html/tryit.asp?filename=tryhtml_basic

you can type the html on the left side and CLICK on the

EDIT THE TEXT AND CLICK ME preview button above to see what it looks like on the right hand side.

 

 

Regards,

S_DS.

John Anthony Oliver  Sunday, December 24, 2006 11:20 PM
Yeah thats pretty much what I'm going for but within a VB app. I click an Option1 ,Opt2, Opt3 ect ect, to populate txtText1 on the left and have the WebBrowser1 on the right show the updated text box as a web HTML format.

All the tuts I've googled have to deal with email type stuff or are over exaggerated code for wht I think should be a pretty simple task but the answer still eludes me...
JustinP  Monday, December 25, 2006 4:50 AM

can you define by what you mean by "as a web html format"?

do you mean whatever you typed into textbox1 you want to show in the webbrowser control?

if you mean show the contents of textbox1 as a web doc you can. you need to place they html body tags around the textbox1 text then show it:

Me.theWebBrowserControl.DocumentText = "<body>" & Me.textBox1.Text & "</body>"

'Me.theWebBrowserControl.Refresh(WebBrowserRefreshOption.Completely) 'C# has this option for some reason

Me.theWebBrowserControl.Update()

 

 

ahmedilyas  Monday, December 25, 2006 3:06 PM

Public Class Form1

Const Header As String = "<html><head></head><body>"

Const closee As String = "</body></html>"

Private Sub cbGo_Click(ByVal sender As Object, _

ByVal e As System.EventArgs) Handles cbGo.Click

WB.DocumentText = Header + TextBox1.Text + closee

End Sub

End Class

ReneeC  Tuesday, December 26, 2006 1:13 AM
Hey thanks for the help, it got me thinking on how to attack this from another perspective and helped me figure it out. Here is how I got it working.


Open App.Path & "\previewcd.html" For Output As #1
Print #1, Text1.Text
Close #1

Me.WebBrowser1.navigate App.Path & "\previewcd.html"

I just placed an empty html template with the header and closing HTML tags in previewcd.html and it's working great now.
JustinP  Tuesday, December 26, 2006 5:38 PM

you should use the .NET classes to open/read files rather than the old methods of VB

alternatively you could just navigate to the path in the webbrowser control as you almost have done..

Me.WebBrowser1.Navigate(Application.StartupPath & "\previewcd.html")

not sure if this is intentional from your code but you are doing nothing in the Textbox apart from reading the file and placing the text in it. Unless you are, as stated earlier, wanting that to be your "editor" :-)

Dim theReader as new System.IO.StreamReader(Application.StartupPath & "\previewcd.html")

Me.Text1.Text = theReader.ReadToEnd()

theReader.Close()

this is the correct .NET way of reading files

ahmedilyas  Tuesday, December 26, 2006 6:09 PM
Yeah, the text1 is simply to display the txt source file and allow on the fly updating if needed. So it can be considered a very very lightweight HTML editor app. As for .NET. I graduated I.T back to 2000. My developer certs are a little antiquated. :-/ I know nothing of .NET. I'm working in Studio 6.

P.S.
Havn't coded anything (except in Flash & director) since 2001. Hence asking the n00b questions. :-P
JustinP  Tuesday, December 26, 2006 6:39 PM

You can use google to search for other answers

Custom Search

More Threads

• FORMAT Function
• Redistribution of .OCX files
• Singleton Pattern - Shared/Synclock confusion...
• how to click any button on web page??
• Custom web server control
• Outlook attachment property
• Tool Tip Question
• Question about hooking
• How to Identified a particular port in Visual basic
• Previously activated window