-
Hi,
I want to do the following:
Form1 has a text box (Text1) and a command button (cmdPreview).
When the user clicks on cmdPreview, I want another form (Form2) to
pop up and show the text in Form1.Text1 as HTML in the browser
control on Form2. I don't need any URL capabilities, just the ability to
preview the contents of Form1.Text1 in html format. Also, I prefer to do this
entirely in memory without having to first write the contents of Form1.Text1 to
a text file and then loading it into the browser control..
Any help and examples would be greatly appreciated..
Dan
-
?
What Kind of text? are you entering html in text1? or just text and then have tags added into the second form...??
If you are just entering text like this...and nothing else special then try this
form1...
Code:
Public Variable as string
Private Sub Button_Click()
Variable = Text1.text
Form2.Show
End sub
then in form 2...
Code:
Private Sub Form_Load()
Text2.text = "<HTML>" & vbcrlf & Form1.Variable & vbcrlf & "</HTML>"
End Sub
I have a feeling that you want more than this though
-
Oops...
I don't know what I was thinkin..Just realized you want it to open in a browser control on form2....
I dont know of any way offhand except to write it to a file then open it with the browser. I am working on something similar and if I come across it I will let you know.
-
I found an example at:
http://www.vbsquare.com/php-bin/prin....php?tipid=379
but it doesn't seem to work.. The webbrowser control does not seem to recognize the ".Body.Innerhtml" function.. Is it possible that there is a newer webbrowser control?
Thanks,
Dan
-
A common mistake, did you put the Webbrowser Control on your form?
-
Try this on for size...
You can use the FileSystemObject (make a reference to Microsoft Scripting Runtime) to write the text to a file, then navigate to that file with you web browser.
Example:
Code:
Private Sub Command1_Click()
Dim fso As New FileSystemObject
Dim loFileText As TextStream
Dim lsFileName As String
' Get a valid name for your file (so you don't overwrite an existing file)
' And place it in the systems temporary folder
lsFileName = fso.GetSpecialFolder(TemporaryFolder) & "\" & fso.GetTempName
' Open the file, write html to it and close it again
Set loFileText = fso.CreateTextFile(lsFileName)
loFileText.WriteLine "<HTML>" & vbCrLf & Text1 & vbCrLf & "</HTML>"
loFileText.Close
' Navigate to the file with your webbrowser control
WebBrowser1.navigate lsFileName
' Memory cleanup
Set loFileText = Nothing
Set fso = Nothing
End Sub
[Edited by seaweed on 11-09-2000 at 04:02 PM]
-
What about this...
Now you got me started...
I just "upgraded" my test program to make a small utility I call "HTML Thief" :)
If you want to try it, create a form and make it fairly big. Put a textbox (Text1) and a webbrowser (WebBrowser1) on it. Set the textbox MultiLine property to TRUE, and Scrollbars to 3-Both.
Position them so they take up most of the form, with only a little room at the bottom for two command buttons. Put the text box and browser right on top of each other, so you can only see one or the other.
Now put two command buttons at the bottom of the form, under the textbox and browser. Name one cmdShowSource and the other cmdShowHTML.
The idea here is that when you are viewing the source, you can edit the HTML in the text box. Then click "View HTML" and you can see what you have created in the browser.
You could potentially copy source from any web site that allows you to do it, and tweak it for your needs, checking your work as you go (alternate between source and HTML view).
Here's the code:
Code:
Option Explicit
Private msTempFileName As String
Private moFileSys As FileSystemObject
Private Sub cmdShowHTML_Click()
Dim loFileText As TextStream
Set loFileText = moFileSys.OpenTextFile(msTempFileName, ForWriting)
loFileText.Write Text1
loFileText.Close
' Navigate to the file with your webbrowser control
With WebBrowser1
.navigate msTempFileName
.Visible = True
End With
' Hide the HTML Source code
Text1.Visible = False
' Memory cleanup
Set loFileText = Nothing
End Sub
Private Sub cmdShowSource_Click()
Text1.Visible = True
WebBrowser1.Visible = False
End Sub
Private Sub Form_Load()
Set moFileSys = New FileSystemObject
' Get an unused file name and add the path to the system's temporary
' folder to it. Create a Text File based on this name and path.
' This file will be used througout the program's run-time
With moFileSys
msTempFileName = .GetSpecialFolder(TemporaryFolder) & "\" & .GetTempName
.CreateTextFile msTempFileName
End With
End Sub
Private Sub Form_Unload(Cancel As Integer)
' Delete the file used in this program
moFileSys.DeleteFile msTempFileName
Set moFileSys = Nothing
End Sub
All you need now is another button that would save the file to a name specified by the user if they want to keep it.
[Edited by seaweed on 11-09-2000 at 04:46 PM]
-
Matthew,
Yes, I did put the control on the form but it doesn't seem to recognize the ".Body.Innerhtml" function of Webbrowser1.Document. Does your's? There seems to be no method, event or property tied to .Document.
Thanks,
Dan