-2

I have a Question to select the last line of the RichTextBox When i click the Button1 it will show the last line in the Messagebox

I tried a lot of codes by it only select the index of the lines i need your help

I want the output like

these are the lines i write in the RichTextBox

1.hello

2.world

3.welcome

when i click the button1 it will show the last line in messagebox

3.welcome // it will appears in the message box

  • 1
    `I tried a lot of codes by it only select the index of the lines` Show that code. You just need to read all text till the and from the index. – Renatas M. Jan 22 '19 at 11:06
  • Thank you for your reply sir, Finally i got the solution It Really works MessageBox.Show(RichTextBox1.Lines(RichTextBox1.Lines.Length - 1)) – ABDUL MAJEED ALI Jan 24 '19 at 05:05

3 Answers3

2

Try this:

MessageBox.Show(RichTextBox.Lines[RichTextBox.Lines.Length -1]);
Stavros S.
  • 117
  • 9
0

Try the below code, considering RichTextBox1 as your RichTextBox name

MessageBox.Show(RichTextBox1.Lines(RichTextBox1.Lines.Length - 1))
LarsTech
  • 80,625
  • 14
  • 153
  • 225
Sreenath Ganga
  • 696
  • 4
  • 19
  • 48
  • The User had put both VB and C# as Tag..c# is already answered ..Thats why vb given...thanks for downvoting – Sreenath Ganga Jan 22 '19 at 12:34
  • Iam working with vb.net for 10 years and using messagebox. – Sreenath Ganga Jan 22 '19 at 15:00
  • 2
    @preciousbetine : Not true. _**VB6**_ uses `MsgBox()`, and the only reason it still exists in VB.NET is for _backwards compatibility_. The [`MessageBox` class](https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.messagebox) is shared between all .NET languages and has existed since **2003**, making the `MsgBox()` function obsolete as of then (that's 16 years ago!). Thus it should _**not**_ be used in today's code. – Visual Vincent Jan 22 '19 at 16:09
  • @preciousbetine : Most functions in the [`Microsoft.VisualBasic` namespace](https://learn.microsoft.com/en-us/dotnet/api/microsoft.visualbasic?view=netframework-4.7.2) (check the docs for each class) only exist for backwards compatibility, so one should try not to use them these days since .NET's own methods are much more well-coded and better designed to work with OOP. – Visual Vincent Jan 22 '19 at 16:18
0

You could try

Messagebox.Show(RTB1.ToString().Split(Constants.vbNewLine).LastOrDefualt.ToString());