In my program I have two child forms, one contains a richtextbox, and the other a webbrowser. When I type into the the text box it displays it in the webbrowser. The problem I am having is that after every key I press I have to click on the richtextbox to continue. I have it focus after every key up event but that does not help. Any thoughts?

THanks

Please show your key handler code. Based on your description I can only surmise that you are some how feeding the key character into the webbrowser.Document text, but that is only a guess. It is hard to offer advice when we have to guess what you are doing.

activate focus to the textbox after keypress

But what is going on in the keyup event handler that is causing it to loose focus? Setting focus may be the ultimate answer, but right now it is more like treating the symptom than the problem.

This is what I have for the key handler:

Private Sub RichTextBox1_TextChanged2(sender As Object, e As EventArgs) Handles RichTextBox1.KeyUp
        System.IO.File.WriteAllText("test.html", "")
        Dim fileWriter As System.IO.StreamWriter
        fileWriter = My.Computer.FileSystem.OpenTextFileWriter("test.html", False)
        fileWriter.Write(RichTextBox1.Text)
        fileWriter.Close()
        Form3child.WebBrowser1.Document.Write(IO.File.ReadAllText("test.html"))
        Form3child.WebBrowser1.Refresh(WebBrowserRefreshOption.Continue)

End Sub

To be honest, I have not tried your code. It's the end of the day, well almost the start of the next, but I did not want to leave you hanging.

I am giving you an alternate method that I have tried and it works.
I assumed that you child forms are MDIChildren, but that does not matter as it work even if not a MDI project.

Form1: MDIParent

Public Class Form1

   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      Form2.MdiParent = Me
      Form2.Show()
      Form3.MdiParent = Me
      Form3.Show()
   End Sub
End Class

Form2: Child with RTB

Public Class Form2
   Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged
      Form3.wb1.DocumentText = RichTextBox1.Text
   End Sub
End Class

Form3: Child with WB

Public Class Form3
   Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      wb1.Navigate("about:blank") ' forces it to create a document
   End Sub
End Class

thanks for the replies, so should i take out the file writer?

Yes. I see no need for it. Once you force the browser to create a blank document, you access that docment directly and modify it's text.

Just curious, what is the point of this other than to see if you can do it?

does not seem to work, i'm probably missing something Here's what I have:

'Mdi Parent Form
Public Class dt_parent

    Private Sub dt_parent_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        dt_child_codeeditor.MdiParent = Me
        dt_child_codeeditor.Show()
        dt_child_webpreview.MdiParent = Me
        dt_child_webpreview.Show()
    End Sub

    Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click
        Me.Close()
    End Sub


End Class

'Form with Richtextbox

    Public Class dt_child_codeeditor

    Private Sub dt_child_codeeditor_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        codeview_rtxt.Size = Me.Size

    End Sub

    Private Sub dt_child_codeeditor_TxtChange(sender As Object, e As EventArgs) Handles MyBase.TextChanged
        dt_child_webpreview.webpreview_brwsr.DocumentText = codeview_rtxt.Text
    End Sub
End Class

'Webbrowser form
Public Class dt_child_webpreview

    Private Sub dt_child_webpreview_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        webpreview_brwsr.Navigate("about:blank")
    End Sub
End Class

I do not see anything in your implementation that should be causing a problem. There is not much to this, so I do not understand why it did not work for you. I'm attaching my implementation.

The only thing I question is your setting the RTB.Size to the form size, but that will not cause an issue. Why not set RTB.Dock=Fill?

What is your development environment?: OS, VS version, 32 or 64 bit?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.