Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Highlight Text

Highlight Text

Scheduled Pinned Locked Moved C#
tutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gmeii
    wrote on last edited by
    #1

    Does anyone know how to highlight a row of text in a richTextBox control.

    H 1 Reply Last reply
    0
    • G gmeii

      Does anyone know how to highlight a row of text in a richTextBox control.

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      If you look at the member documentation[^] for the RichTextBox class in the .NET Framework SDK, you'll find several properties that begin with Selection* or Selected*. 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 the RichTextBox. The RichTextBox 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 the RichTextBox 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 your RichTextBox, set its ShowSelectionMargin property to true.

      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]

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups