BP Forums
I have searched all over for this - Printable Version

+- BP Forums (https://bpforums.info)
+-- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=55)
+--- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=56)
+---- Forum: VB.NET (Visual Basic 2010/2008) (https://bpforums.info/forumdisplay.php?fid=8)
+----- Forum: Programming Help (https://bpforums.info/forumdisplay.php?fid=9)
+----- Thread: I have searched all over for this (/showthread.php?tid=379)



I have searched all over for this - VicDesigns - 08-05-2011

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: -->


Re: I have searched all over for this - brandonio21 - 08-05-2011

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.


Re: I have searched all over for this - VicDesigns - 08-05-2011

Hi Brandon,

Thanks for that. But it doesn't work I'm afraid.


Re: I have searched all over for this - brandonio21 - 08-05-2011

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



Re: I have searched all over for this - VicDesigns - 08-05-2011

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.


Re: I have searched all over for this - brandonio21 - 08-05-2011

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


Re: I have searched all over for this - VicDesigns - 08-05-2011

Okay, I have done that and now get an error about RichTextBox1 cannot be converted to System.Windows.Form.RichTextBox


Re: I have searched all over for this - brandonio21 - 08-06-2011

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]


Re: I have searched all over for this - VicDesigns - 08-06-2011

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: -->


Re: I have searched all over for this - brandonio21 - 08-06-2011

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.


Re: I have searched all over for this - VicDesigns - 08-06-2011

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: -->


Re: I have searched all over for this - brandonio21 - 08-07-2011

Hahahahah! Well unwrinkle those brains! We have a problem to solve!! How random are the numbers? Could we possibly get a screenshot?


Re: I have searched all over for this - VicDesigns - 08-07-2011

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 -->


Re: I have searched all over for this - brandonio21 - 08-07-2011

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!


Re: I have searched all over for this - VicDesigns - 08-08-2011

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 -->


Re: I have searched all over for this - xolara - 09-09-2011

You kind sir did just discover The Matrix!

^^