|
-
Dec 2nd, 2011, 12:44 PM
#1
Thread Starter
Member
[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.
-
Dec 2nd, 2011, 01:10 PM
#2
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.
-
Dec 2nd, 2011, 01:14 PM
#3
Thread Starter
Member
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.
-
Dec 2nd, 2011, 01:28 PM
#4
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.
-
Dec 2nd, 2011, 01:36 PM
#5
Thread Starter
Member
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?
-
Dec 2nd, 2011, 01:48 PM
#6
Re: Using the Gecko Web Browser control to display textbox input as HTML in VB
 Originally Posted by stepdragon
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.
-
Dec 2nd, 2011, 01:57 PM
#7
Thread Starter
Member
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!
-
Dec 2nd, 2011, 02:05 PM
#8
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:
Public Class Form1 Dim InputCounter As Integer = 20 Dim TextContent As String = "" Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick InputCounter -= 1 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 End Sub Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged InputCounter = 20 End Sub End Class
Last edited by stepdragon; Dec 2nd, 2011 at 02:23 PM.
-
Dec 2nd, 2011, 02:09 PM
#9
Thread Starter
Member
Re: Using the Gecko Web Browser control to display textbox input as HTML in VB
Thanks so much!
-
Dec 2nd, 2011, 02:24 PM
#10
Thread Starter
Member
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?
-
Dec 2nd, 2011, 02:38 PM
#11
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.
-
Dec 2nd, 2011, 02:42 PM
#12
Thread Starter
Member
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
-
Dec 2nd, 2011, 02:55 PM
#13
Re: Using the Gecko Web Browser control to display textbox input as HTML in VB
First result in google yields:
vb.net Code:
My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData
-
Dec 2nd, 2011, 02:59 PM
#14
Thread Starter
Member
Re: Using the Gecko Web Browser control to display textbox input as HTML in VB
Thanks very much! Should have googled that before asking.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|