Richtextbox and ScrollToCaret

M

MIchael Ullrich

Hi,

I have an Application with many child-forms. the child-forms have
richtext-boxes.
For adding to the boxes I have the following event:
Private Sub StatusText_TextChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles StatusText.TextChanged
If StatusText.TextLength > 10 Then
StatusText.Select(StatusText.TextLength, 0)
StatusText.Focus()
StatusText.ScrollToCaret()
End If
End Sub

The problem is now, that the focus is always moved to the
richtext-box. Is there a way to notice the currently focused control,
so that I can set back the focus to the last control.
Or is there a way to go to the end of the richtextbox-text each time I
add something?

Thanks

Mike
 
H

Herfried K. Wagner [MVP]

* (e-mail address removed) (MIchael Ullrich) scripsit:
The problem is now, that the focus is always moved to the
richtext-box. Is there a way to notice the currently focused control,
so that I can set back the focus to the last control.
Or is there a way to go to the end of the richtextbox-text each time I
add something?

Quick and Dirty:

\\\
Dim ctr As Control = Me.ActiveControl
With Me.RichTextBox1
.Focus()
.AppendText("Hallo")
.ScrollToCaret()
End With
ctr.Focus()
///
 
F

Fritz

Hi,

but I have a Multi-Child for application and the focus usually is not in
the active childform.
More quick and dirty I have added this to the MDI-container:

Public Sub StoreControl()
cStoredMdiChild = Me.ActiveMdiChild
cStoredControl = Me.ActiveMdiChild.ActiveControl()
End Sub

Public Sub ReStoreControl()
Me.ActivateMdiChild(cStoredMdiChild)
cStoredMdiChild.ActiveControl = cStoredControl
End Sub

Each Child-form knows it`s container and can call the Methods.
It works quite ok.
But the click-Events of the buttons have to be replaced by the
MouseDown-Event
Bye

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top