|
-
Nov 5th, 2003, 02:44 PM
#1
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?
-
Nov 5th, 2003, 04:05 PM
#2
Post a sample project (yes i am too lazy to cut and paste) and maybe we can figure it out.
-
Nov 5th, 2003, 05:26 PM
#3
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
-
Nov 5th, 2003, 05:37 PM
#4
Is txtBoxChild where this is all happening at? The same control you refer to in the event?
-
Nov 5th, 2003, 05:40 PM
#5
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.
-
Nov 5th, 2003, 06:11 PM
#6
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.
-
Nov 5th, 2003, 06:43 PM
#7
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?
-
Nov 5th, 2003, 07:15 PM
#8
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:
StatusBarChildCurrentLine.Text = txtBoxChild.GetLineFromCharIndex(txtBoxChild.SelectionStart)
Although I think that is zero based. Also it should probably change on selction change:
VB Code:
Private Sub txtBoxChild_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtBoxChild.SelectionChanged
StatusBarChildCurrentLine.Text = txtBoxChild.GetLineFromCharIndex(txtBoxChild.SelectionStart)+1
End Sub
-
Nov 5th, 2003, 07:21 PM
#9
I found a way! I'm such a sucker for a challenge.
VB Code:
Private Sub txtBoxChild_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtBoxChild.SelectionChanged
StatusBarChildCurrentLine.Text = txtBoxChild.GetLineFromCharIndex(txtBoxChild.SelectionStart) + 1
StatusBarChildtotalLines.Text = txtBoxChild.GetLineFromCharIndex(Integer.MaxValue) + 1
End Sub
-
Nov 5th, 2003, 07:24 PM
#10
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
-
Nov 5th, 2003, 07:26 PM
#11
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|