Dim line_count As Integer = mainEditor.Lines.Length
Dim linecounter As Integer = line_count
linecounter += 1
line_count = 0
lineNumbers.Text = ""
While line_count < linecounter
line_count += 1
lineNumbers.Text += line_count + "\n"
End While
Show Number of Lines In Rich Text BoxLike in Visual Studio and Dreamweaver
Page 1 of 1
6 Replies - 8409 Views - Last Post: 01 September 2010 - 05:14 AM
#1
Show Number of Lines In Rich Text Box
Posted 31 August 2010 - 06:01 AM
I have 2 panels set up, one contains the rich text box the other one contains a single label. The am currently using the following code however it is not working. Help would be greatly appreciated.
Replies To: Show Number of Lines In Rich Text Box
#2
Re: Show Number of Lines In Rich Text Box
Posted 31 August 2010 - 06:16 AM
Hi!
Ok, what is the problem? What errors do you get? What do you want to get? It seems to me that you are just looping as many times as there are rows and writing each rownumber followed by a newline...
Regards
Jens
PS: Cleaned and "beautified" (in my opinion) your code a little. Now it does count the rows (one to many) but I don't know if this is what you wanted. Check the code and come back if you don't understand.
PPS: Added a button to the form in order to get the code running. You didn't show where you'd put it so...
Ok, what is the problem? What errors do you get? What do you want to get? It seems to me that you are just looping as many times as there are rows and writing each rownumber followed by a newline...
Regards
Jens
PS: Cleaned and "beautified" (in my opinion) your code a little. Now it does count the rows (one to many) but I don't know if this is what you wanted. Check the code and come back if you don't understand.
PPS: Added a button to the form in order to get the code running. You didn't show where you'd put it so...
Option Explicit On
Option Strict On
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim linecounter As Integer = 0
Dim line_count As Integer = 0
linecounter = mainEditor.Lines.Length + 1
lineNumbers.Text = ""
While line_count < linecounter
line_count += 1
lineNumbers.Text += line_count.ToString() + Environment.NewLine()
End While
End Sub
End Class
This post has been edited by jens: 31 August 2010 - 07:10 AM
#3
Re: Show Number of Lines In Rich Text Box
Posted 31 August 2010 - 07:18 AM
Can't you just use
Or am I mis-understanding what you're trying to do?
lineNumbers.Text = mainEditor.Lines.Count()
Or am I mis-understanding what you're trying to do?
#4
Re: Show Number of Lines In Rich Text Box
Posted 31 August 2010 - 08:08 AM
I mean like in Dreamweaver and Visual studio where on the left it shows the line numbers.
Edit: Oh wow, thanks, the only problem is that if you have a long string of text and then press enter the line count continues, this might be a bit confusing so I took a screenshot:
http://i34.tinypic.com/1t51tk.jpg
Edit: Oh wow, thanks, the only problem is that if you have a long string of text and then press enter the line count continues, this might be a bit confusing so I took a screenshot:
http://i34.tinypic.com/1t51tk.jpg
This post has been edited by Protego: 31 August 2010 - 08:15 AM
#5
Re: Show Number of Lines In Rich Text Box
Posted 31 August 2010 - 09:05 AM
Could you use bullets and then send Ctrl+Shift+L to switch the bullets to numbers?
Here's an example of what I'm talking about
Create 2 buttons, Button1 and Button2 and set their .Text property to # On and # off
In Button1_Click (# On) add the following:
In Button2_Click (# Off) add the following:
See if that gives you something to work with.
Here's an example of what I'm talking about
Create 2 buttons, Button1 and Button2 and set their .Text property to # On and # off
In Button1_Click (# On) add the following:
mainEditor.SelectAll()
mainEditor.Focus()
SendKeys.Send("^+L") 'switch selection to bullets
SendKeys.Send("^+L") 'switch selection to numbers
Button1.Enabled = False
In Button2_Click (# Off) add the following:
mainEditor.SelectionBullet = False Button1.Enabled = True
See if that gives you something to work with.
This post has been edited by CharlieMay: 31 August 2010 - 09:06 AM
#6
Re: Show Number of Lines In Rich Text Box
Posted 01 September 2010 - 04:52 AM
Ok so this is what I have now:
But now it just keeps looping and if I remove the delselectall if just freezes.
Private Sub mainEditor_KeyDown1(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles mainEditor.KeyDown
Dim prevent As Integer = 0
While prevent = 0
mainEditor.SelectAll()
mainEditor.Focus()
SendKeys.Send("^+L") 'switch selection to bullets
SendKeys.Send("^+L") 'switch selection to numbers
mainEditor.DeselectAll()
prevent += 1
End While
End Sub
But now it just keeps looping and if I remove the delselectall if just freezes.
#7
Re: Show Number of Lines In Rich Text Box
Posted 01 September 2010 - 05:14 AM
With what you're trying to achieve with prevent. Notice that you are always setting prevent to 0 and then trying to perform the while if prevent = 0. Prevent ALWAYS equals 0 with the way your code is written.
Move the Dim Prevent As Integer = 0 to just below the Public Class <formname> and it should work.
The reason I set it up in my example as I did, was to give you the option to toggle the line numbers on and off. If you always want them on you can just do the run the routine in the form_shown event
This will start the RTB with line number bullets.
Move the Dim Prevent As Integer = 0 to just below the Public Class <formname> and it should work.
The reason I set it up in my example as I did, was to give you the option to toggle the line numbers on and off. If you always want them on you can just do the run the routine in the form_shown event
Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
mainEditor.SelectAll()
mainEditor.Focus()
SendKeys.Send("^+L")
SendKeys.Send("^+L")
End Sub
This will start the RTB with line number bullets.
This post has been edited by CharlieMay: 01 September 2010 - 05:22 AM
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote





|