Results 1 to 11 of 11

Thread: Why does this break the RichTextBox?

  1. #1

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Why does this break the RichTextBox?

    Note: Yes I know 2 seperate parts of the statusbar display the samething, that's just for testing it, lol
    Code:
    TotalLines = Convert.ToString(txtBoxChild.Lines.LongLength)
            StatusBarChildtotalLines.Text = "Total Lines: " + TotalLines
            StatusBarChildCurrentLine.Text = Convert.ToString(txtBoxChild.Lines.Length)
            If RecentSave = True Then
                RecentSave = False
                mnuChildSave.Enabled = True
            End If
    If I put that in the TextChanged event, or KeyPress event for the TextBox, half the TextBox functions STOP working (like undo() and redo())

    Why do they stop working? They are read-only functions, I don't see why that would make them not work!

    How else am I supposed to update my statusbar when the user changes something?

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Post a sample project (yes i am too lazy to cut and paste) and maybe we can figure it out.

  3. #3

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Originally posted by Edneeis
    Post a sample project (yes i am too lazy to cut and paste) and maybe we can figure it out.
    VB isn't in front of my right now

    I'm not sure what the problem is... maybe I should try a thread

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Is txtBoxChild where this is all happening at? The same control you refer to in the event?

  5. #5

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Originally posted by Edneeis
    Is txtBoxChild where this is all happening at? The same control you refer to in the event?
    yes, it's a richtextbox and the undo() and redo() functions break when I put the code I mentioned in the textchanged even, or even in keypress.

  6. #6
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    I don't know why but I know what. The reference to the Line property is what breaks it. If you comment that out it works again. Something about how it gets the lines must reset the undo, that would be my guess. Report it as a bug to MS or if your software isn't legit then tell me and I'll report it.

    Yeah if you check the UndoActionName it has a value until you reference the lines property after which it is blank.

    I found this but it is from a cached page and the actual topic didn't get cached:
    http://216.239.53.104/search?q=cache...ng_en&ie=UTF-8

    The title was 'RichTextBox: Accessing Lines kill undo Events.'
    Last edited by Edneeis; Nov 5th, 2003 at 06:27 PM.

  7. #7

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Yeah I figured it was a bug. Feel free to submit it to MS.

    Is there any way to get the total lines number and the current line's number of a richtextbox without using the built in functions?

  8. #8
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    It seems to be whenever you reference or set anything related to the text or rtf properties via code it then clears any undo data. You can probably API it to get the lines, which seems pretty stupid. I can get the current line but not the total lines without clearing the undo. Here is the currentline:
    VB Code:
    1. StatusBarChildCurrentLine.Text = txtBoxChild.GetLineFromCharIndex(txtBoxChild.SelectionStart)
    Although I think that is zero based. Also it should probably change on selction change:
    VB Code:
    1. Private Sub txtBoxChild_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtBoxChild.SelectionChanged
    2.         StatusBarChildCurrentLine.Text = txtBoxChild.GetLineFromCharIndex(txtBoxChild.SelectionStart)+1
    3.     End Sub

  9. #9
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    I found a way! I'm such a sucker for a challenge.
    VB Code:
    1. Private Sub txtBoxChild_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtBoxChild.SelectionChanged
    2.         StatusBarChildCurrentLine.Text = txtBoxChild.GetLineFromCharIndex(txtBoxChild.SelectionStart) + 1
    3.         StatusBarChildtotalLines.Text = txtBoxChild.GetLineFromCharIndex(Integer.MaxValue) + 1
    4.     End Sub

  10. #10

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Thanks alot, I think I got totallines to work now as well:
    Code:
    Private Sub txtBoxChild_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtBoxChild.SelectionChanged
            StatusBarChildCurrentLine.Text = "Current Line: " + Convert.ToString(txtBoxChild.GetLineFromCharIndex(txtBoxChild.SelectionStart))
            StatusBarChildtotalLines.Text = "Total Lines: " + Convert.ToString(txtBoxChild.GetLineFromCharIndex(txtBoxChild.SelectionStart.MaxValue))
        End Sub

    EDIT: Damn it, I go off and figure something out and you just have to post before me

    lol, thanks though

  11. #11
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Originally posted by kasracer
    EDIT: Damn it, I go off and figure something out and you just have to post before me

    lol, thanks though
    Well you now me I'm on old thunder stealer!

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