Results 1 to 14 of 14

Thread: [RESOLVED] Using the Gecko Web Browser control to display textbox input as HTML in VB

  1. #1

    Thread Starter
    Member cowboycoding's Avatar
    Join Date
    Jun 2011
    Posts
    34

    Resolved [RESOLVED] Using the Gecko Web Browser control to display textbox input as HTML in VB

    Hi!
    I'd like to use the GeckoWebBrowser control to display HTML code that I type (or paste) into a TextBox. Here is the (nonworking) code I have:
    Code:
    GeckoWebBrowser1.Text = textBox1.Text()
    All help greatly appreciated!
    Last edited by cowboycoding; Dec 2nd, 2011 at 12:51 PM.

  2. #2
    Hyperactive Member stepdragon's Avatar
    Join Date
    Aug 2011
    Location
    Cincinnati
    Posts
    288

    Re: Using the Gecko Web Browser control to display textbox input as HTML in VB

    You could try saving the contents of the textbox to a temporary file, and then navigating to that file.

    If you're wrong, you'll learn. If I'm wrong, I'll learn. Try something new and go from there. That's how we improve.

    CodeBank: VB.Net - Simple Proper Image Scaling in Correct Aspect Ratio - Star Rating Control
    Useful Links: HOW TO USE CODE TAGS

  3. #3

    Thread Starter
    Member cowboycoding's Avatar
    Join Date
    Jun 2011
    Posts
    34

    Re: Using the Gecko Web Browser control to display textbox input as HTML in VB

    Thank you, but it would be to inefficient for my purposes. I set that code in the keypress event do it could be viewed in realtime.
    Last edited by cowboycoding; Dec 2nd, 2011 at 01:17 PM.

  4. #4
    Hyperactive Member stepdragon's Avatar
    Join Date
    Aug 2011
    Location
    Cincinnati
    Posts
    288

    Re: Using the Gecko Web Browser control to display textbox input as HTML in VB

    I wouldn't do it that way anyways... At very least, I would have a timer going, and each time you hit a key it resets a counter to lets say 10. so that you can type multiple characters and it will display it once you pause for a second.

    I would venture to say (no testing mind you, just a guess) that it would take more time for the page to render than saving a simple text file... and I also think it wouldn't be necessary to raise a navigate event on each keypress. That's just going to slow down the user's experience rather than offer a live preview. Like I said, I think waiting half a second after the most recent keystroke would be more than enough. and then you'd be able to safely do a save / load.

    If you're wrong, you'll learn. If I'm wrong, I'll learn. Try something new and go from there. That's how we improve.

    CodeBank: VB.Net - Simple Proper Image Scaling in Correct Aspect Ratio - Star Rating Control
    Useful Links: HOW TO USE CODE TAGS

  5. #5

    Thread Starter
    Member cowboycoding's Avatar
    Join Date
    Jun 2011
    Posts
    34

    Re: Using the Gecko Web Browser control to display textbox input as HTML in VB

    Wouldn't it consume more resources saving a new text file every time you typed a letter?
    http://openexpressions.sourceforge.net
    http://www.cowboycomputers.TK
    I appreciate helping when my helping is appreciated.
    I always appreciate your help as well.

  6. #6
    Hyperactive Member stepdragon's Avatar
    Join Date
    Aug 2011
    Location
    Cincinnati
    Posts
    288

    Re: Using the Gecko Web Browser control to display textbox input as HTML in VB

    Quote Originally Posted by stepdragon View Post
    I wouldn't do it that way anyways... At very least, I would have a timer going, and each time you hit a key it resets a counter to lets say 10. so that you can type multiple characters and it will display it once you pause for a second.

    I would venture to say (no testing mind you, just a guess) that it would take more time for the page to render than saving a simple text file... and I also think it wouldn't be necessary to raise a navigate event on each keypress. That's just going to slow down the user's experience rather than offer a live preview. Like I said, I think waiting half a second after the most recent keystroke would be more than enough. and then you'd be able to safely do a save / load.
    I did offer a solution to that. Albeit timers aren't the best choice. In a perfect world having a seperate thread keeping track of that would be ideal. But a well thought out backgroundworker could get it done as well.

    Yes it would slow down your program if you saved the file every time you typed a letter, but so would attempting to display a webpage... If you lessen the number of times it is displayed (every keypress is a bit excessive) you can use a more robust method of displaying. in this example the one that we know works.

    If you're wrong, you'll learn. If I'm wrong, I'll learn. Try something new and go from there. That's how we improve.

    CodeBank: VB.Net - Simple Proper Image Scaling in Correct Aspect Ratio - Star Rating Control
    Useful Links: HOW TO USE CODE TAGS

  7. #7

    Thread Starter
    Member cowboycoding's Avatar
    Join Date
    Jun 2011
    Posts
    34

    Re: Using the Gecko Web Browser control to display textbox input as HTML in VB

    Would you mind giving me a good example for that? Thanks for your help!
    http://openexpressions.sourceforge.net
    http://www.cowboycomputers.TK
    I appreciate helping when my helping is appreciated.
    I always appreciate your help as well.

  8. #8
    Hyperactive Member stepdragon's Avatar
    Join Date
    Aug 2011
    Location
    Cincinnati
    Posts
    288

    Re: Using the Gecko Web Browser control to display textbox input as HTML in VB

    Ok, here's the code. It uses a timer to only update once the user pauses for a short amount of time. Also note that I don't have the same browser control you have, so I used the default webbrowser control. Just replace that navigate line with whatever your browser uses to navigate with. I have tested this and it works.

    vb.net Code:
    1. Public Class Form1
    2.  
    3.     Dim InputCounter As Integer = 20
    4.     Dim TextContent As String = ""
    5.  
    6.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    7.         InputCounter -= 1
    8.  
    9.         If InputCounter <= 0 Then
    10.             If TextContent <> TextBox1.Text Then
    11.                 Dim objWriter As New System.IO.StreamWriter(Application.StartupPath & "\test.html")
    12.                 objWriter.Write(TextBox1.Text)
    13.                 objWriter.Close()
    14.  
    15.                 WebBrowser1.Navigate(Application.StartupPath & "\test.html")
    16.  
    17.                 TextContent = TextBox1.Text
    18.             End If
    19.         End If
    20.  
    21.  
    22.     End Sub
    23.  
    24.     Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
    25.         InputCounter = 20
    26.     End Sub
    27.  
    28. End Class
    Last edited by stepdragon; Dec 2nd, 2011 at 02:23 PM.

    If you're wrong, you'll learn. If I'm wrong, I'll learn. Try something new and go from there. That's how we improve.

    CodeBank: VB.Net - Simple Proper Image Scaling in Correct Aspect Ratio - Star Rating Control
    Useful Links: HOW TO USE CODE TAGS

  9. #9

    Thread Starter
    Member cowboycoding's Avatar
    Join Date
    Jun 2011
    Posts
    34

    Re: Using the Gecko Web Browser control to display textbox input as HTML in VB

    Thanks so much!
    http://openexpressions.sourceforge.net
    http://www.cowboycomputers.TK
    I appreciate helping when my helping is appreciated.
    I always appreciate your help as well.

  10. #10

    Thread Starter
    Member cowboycoding's Avatar
    Join Date
    Jun 2011
    Posts
    34

    Re: Using the Gecko Web Browser control to display textbox input as HTML in VB

    Thanks again! I'll try that.
    Is there a way to save stuff in the users documents folder so I don't have to do administrator stuff?
    http://openexpressions.sourceforge.net
    http://www.cowboycomputers.TK
    I appreciate helping when my helping is appreciated.
    I always appreciate your help as well.

  11. #11
    Hyperactive Member stepdragon's Avatar
    Join Date
    Aug 2011
    Location
    Cincinnati
    Posts
    288

    Re: Using the Gecko Web Browser control to display textbox input as HTML in VB

    Code:
            If InputCounter <= 0 Then
                If TextContent <> TextBox1.Text Then
                    Dim objWriter As New System.IO.StreamWriter(Application.StartupPath & "\test.html")
                    objWriter.Write(TextBox1.Text)
                    objWriter.Close()
     
                    WebBrowser1.Navigate(Application.StartupPath & "\test.html")
     
                    TextContent = TextBox1.Text
                End If
            End If
    Just replace the Highlighted Text with "Your\Chosen\Path\And.File". It would also be a good idea to hold that in its own variable so that you can change both of them by changing the variable. It was poor writing on my part for doing it that way.

    If you're wrong, you'll learn. If I'm wrong, I'll learn. Try something new and go from there. That's how we improve.

    CodeBank: VB.Net - Simple Proper Image Scaling in Correct Aspect Ratio - Star Rating Control
    Useful Links: HOW TO USE CODE TAGS

  12. #12

    Thread Starter
    Member cowboycoding's Avatar
    Join Date
    Jun 2011
    Posts
    34

    Re: Using the Gecko Web Browser control to display textbox input as HTML in VB

    I guess I am saying is there a way to save it in the users Appdata folder. Example: C:\Users\--Here is where I have the problem--\AppData\Local
    http://openexpressions.sourceforge.net
    http://www.cowboycomputers.TK
    I appreciate helping when my helping is appreciated.
    I always appreciate your help as well.

  13. #13
    Hyperactive Member stepdragon's Avatar
    Join Date
    Aug 2011
    Location
    Cincinnati
    Posts
    288

    Re: Using the Gecko Web Browser control to display textbox input as HTML in VB

    First result in google yields:

    vb.net Code:
    1. My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData

    If you're wrong, you'll learn. If I'm wrong, I'll learn. Try something new and go from there. That's how we improve.

    CodeBank: VB.Net - Simple Proper Image Scaling in Correct Aspect Ratio - Star Rating Control
    Useful Links: HOW TO USE CODE TAGS

  14. #14

    Thread Starter
    Member cowboycoding's Avatar
    Join Date
    Jun 2011
    Posts
    34

    Re: Using the Gecko Web Browser control to display textbox input as HTML in VB

    Thanks very much! Should have googled that before asking.
    http://openexpressions.sourceforge.net
    http://www.cowboycomputers.TK
    I appreciate helping when my helping is appreciated.
    I always appreciate your help as well.

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