Results 1 to 8 of 8

Thread: browser control

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,091
    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

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Question ?

    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

    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Cool 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.
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,091
    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

  5. #5
    Guest
    A common mistake, did you put the Webbrowser Control on your form?

  6. #6
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357

    Talking 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]
    ~seaweed

  7. #7
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357

    Lightbulb 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]
    ~seaweed

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,091
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width