views:

24

answers:

1

Hello,

this code underlines all Text in the Textbox, can I underline only specific Text?

Brush brush = Brushes.Blue;

            Pen pen = new Pen(brush,2);

            TextBox tb1 = new TextBox();
            tb1.AcceptsReturn = true;

            tb1.Text = "This is a very long Text not?";            

            TextDecoration textDec = new TextDecoration(TextDecorationLocation.Underline,pen,1,TextDecorationUnit.Pixel,TextDecorationUnit.FontRecommended);

            tb1.TextDecorations.Add(textDec);

            tb1.Width = 400;
            tb1.Height = 30;
            this.AddChild(tb1);
+3  A: 

The TextBox doesn't provide the ability to alter characteristics for individual characters. It's an all or none control.

The RichTextBox is the control you need.

Tergiver