Highlight Text
-
If you look at the member documentation[^] for the
RichTextBox
class in the .NET Framework SDK, you'll find several properties that begin withSelection*
orSelected*
. Many of those properties give you several different ways of selecting text based on what you want to do. Keep in mind that there's not really a row, though. There are paragraphs that are wrapped and "rows" are formed by whatever words fit within the current width of theRichTextBox
. TheRichTextBox
already does this, though, if you click the far left edge of the control. In applications like WordPad (which use the Rich-Edit control, which theRichTextBox
class in .NET encapsulates), the margins are set wider so that it's easier to click and select a line. To do the same in yourRichTextBox
, set itsShowSelectionMargin
property totrue
.using System;
using System.Drawing;
using System.Windows.Forms;
class Test : Form
{
static void Main()
{
Application.Run(new Test());
}
Test()
{
RichTextBox rt = new RichTextBox();
Controls.Add(rt);
rt.Dock = DockStyle.Fill;
rt.ShowSelectionMargin = true;
Text = "Test";
}
}This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog]