Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I have searched all over for this
#1
I have searched Googly Woogly everywhere over the past couple of days for this and can't find a definite solution anywhere.

What I need is some code or a component or something that will allow me to place a Horizontal Ruler and a Vertical Number List on a Rich Text Box in Visual Basic 2010.
The vertical numberlist would be automated where a new line creates a new number etc. You know what I am getting at.
Anyways, does anyone have that magical piece of code or know where one could get it?
<!-- sConfusedhock: --><img src="{SMILIES_PATH}/icon_eek.gif" alt="Confusedhock:" title="Shocked" /><!-- sConfusedhock: -->
#2
Gotta say I've never heard "Googly Woogly" Used as a term before, but I know what you are getting at.

For the vertical line counter, it is very simple to code. All you need to do is setup a textbox to the left of your main richtextbox, and give it some type of code like this. (Please note, this code has not been tested)

Code:
Sub reLine(ByVal rtb as richtextbox)
'Where textbox1 is the textbox on the side of the TextBox1.Text = ""
Dim i As Integer = 1
Do Until TextBox1.Lines.Count = rtb.Lines.Count
TextBox1.AppendText(i.ToString + vbNewLine)
i = i + 1
Loop
End sub

You can obviously do more advanced things with this code, but here is the jist of it.
My Blog | My Setup | My Videos | Have a wonderful day.
#3
Hi Brandon,

Thanks for that. But it doesn't work I'm afraid.
#4
Really? I just tested it and it seems to work. Call this sub when the richtextbox's text has changed. For example...

Code:
Sub rtb_changed handles RichTextBox1.TextChanged
reLine(RichTextbox1)
End sub
My Blog | My Setup | My Videos | Have a wonderful day.
#5
Nope. The text box to the left just stays blank.
Also, when I use:
Code:
Sub rtb_changed handles RichTextBox1.TextChanged
reLine(RichTextbox1)
End sub
It says reline is undeclared.
#6
Well, you need to combine the two bits of code.. So just insert this whole block into your form:

Code:
Sub rtb_changed handles RichTextBox1.TextChanged
reLine(RichTextbox1)
End sub

Sub reLine(ByVal rtb as richtextbox)
'Where textbox1 is the textbox on the side of the TextBox1.Text = ""
Dim i As Integer = 1
Do Until TextBox1.Lines.Count = rtb.Lines.Count
TextBox1.AppendText(i.ToString + vbNewLine)
i = i + 1
Loop
End sub

And make sure that the textbox on the left is called textbox1
My Blog | My Setup | My Videos | Have a wonderful day.
#7
Okay, I have done that and now get an error about RichTextBox1 cannot be converted to System.Windows.Form.RichTextBox
#8
Well that's strange... Make sure that on your form the RichTextBox1 is actually a richtextbox.

Attached is a project file of a sample setup using this code, hopefully it helps you.

[attachment=0]<!-- ia0 -->LineCounter.zip<!-- ia0 -->[/attachment]


Attached Files
.zip   LineCounter.zip (Size: 67.81 KB / Downloads: 574)
My Blog | My Setup | My Videos | Have a wonderful day.
#9
I am definitely doing something wrong.
I removed the richtextbox and placed a new one there, inserted the code you provided, ran debug and the whole textbox on the left went crazy splurting out random numbers.
I presume it is into form1.vb I am putting the code right?
<!-- sConfusedhock: --><img src="{SMILIES_PATH}/icon_eek.gif" alt="Confusedhock:" title="Shocked" /><!-- sConfusedhock: -->
#10
Well, the good news is, you got no errors! And atleast the textbox is splurting out something, lol!

Here is the exact code you need, sir.

Code:
sub rtb() Handles RichTextBox1.textchanged
TextBox1.Text = ""
        Dim i As Integer = 1
        Do Until TextBox1.Lines.Count = RichTextBox1.Lines.Count
            TextBox1.AppendText(i.ToString + vbNewLine)
            i = i + 1
        Loop
end sub
If you copy and paste this code into your form, it is guaranteed to work.
My Blog | My Setup | My Videos | Have a wonderful day.
#11
LMAO
It's still shooting out random numbers. lol
Oh my brains have gone wrinkled. LOL <!-- s:lol: --><img src="{SMILIES_PATH}/icon_lol.gif" alt=":lol:" title="Laughing" /><!-- s:lol: -->
#12
Hahahahah! Well unwrinkle those brains! We have a problem to solve!! How random are the numbers? Could we possibly get a screenshot?
My Blog | My Setup | My Videos | Have a wonderful day.
#13
lol They are basically as follows:

205
2
305
3
405
4
505
5
605
6

etc etc etc. And goes really fast like it's doing something from The Matrix or something hahaha.

Anyways, I did the following, which works in adding the line numbers. But with something like:

1||
2||
3||

etc, instead of just

1
2
3

etc.

However, it doesn't take the line numbers away when you go back up:

Code:
Private Sub RichTextBox1_EnterKeyPressed(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles RichTextBox1.KeyDown
        Dim numlinecount As Integer
        If e.KeyData = Keys.Enter Then
            numlinecount = (TextBox1.GetLineFromCharIndex(TextBox1.Text.Length)) + 1
            TextBox1.AppendText(CStr(numlinecount) & vbLf)
        End If
    End Sub

Have NFI what's going on lol.

Told you I was No0bie. <!-- sTongue --><img src="{SMILIES_PATH}/icon_razz.gif" alt="Tongue" title="Razz" /><!-- sTongue -->
#14
Well I have to say that this whole thing is definitely a little strange...

I don't really know how to fix it because I have no idea where the 405 and stuff is coming from, but if you want to delete the entries when you go back up, I think all you need to do is add
Code:
TextBox1.text = ""
Which will clear the textbox and allow it to redraw? Not sure if this will work, but hey, why not!

I am just baffled at why you are having problems getting this to work, I mean, the code provided should work no problem!
My Blog | My Setup | My Videos | Have a wonderful day.
#15
Yeah I have no doubt it should work.
I am on my work computer now so as soon as I get a minute when the boss is not looking I will give it a go. <!-- sWink --><img src="{SMILIES_PATH}/icon_e_wink.gif" alt="Wink" title="Wink" /><!-- sWink -->
#16
You kind sir did just discover The Matrix!

^^
Website: <!-- m --><a class="postlink" href="http://www.PBAProductions.com">http://www.PBAProductions.com</a><!-- m -->
E-Mail: <!-- e --><a href="mailtoTongueatrick@AriSystems.Org">Patrick@AriSystems.Org</a><!-- e -->
Skype: Qwaxer
Youtube: Qwaxer
[Image: 2hnx8av.jpg]


Forum Jump:


Users browsing this thread: 1 Guest(s)