VB 2010 - RichTextBox: how can i protect a text on back of controls?


  • usind the controls coolletion, we can add controls on RichTextBox. but the control can be moved(even using enter\backspace keys).

    we can write text on back of controls, but i need avoid these.

    the best is using the SelectionProtect... but isn't working :(

    'these function is on my PlusRichTextBox, that Inherist from RichTextBox
    Public Sub InsertControl(ByVal ctrlControl As Control)
            Dim LineIndex As Integer = Me.GetLineFromCharIndex(Me.SelectionStart)
            Dim s As Point = Me.GetPositionFromCharIndex(LineIndex)
            For i As Integer = s.Y To s.Y + ctrlControl.Height
                Me.SelectionProtected = True
                Me.SelectedText = vbNewLine
                i += Me.SelectionFont.Height
                If i >= (s.Y + Me.Height) Then Exit For
            Me.SelectionProtected = False
            ctrlControl.Location = s
        End Sub

    if the RichTextBox it's empty the exact lines are protected, but if theres some lines, isn't.

    can anyone advice me?

    (i need protect the text, for we don't write on back of controls)

    Saturday, April 8, 2017 10:51 AM