Wednesday, March 9, 2011

TextBox and RichTextBox (Code)

Speaking of the TextBox control, the Windows Presentation Foundation supports the two we've come to expect:
Control
       TextBoxBase (abstract)
                  TextBox
                  RichTextBox
Although the TextBox has content, it is not considered a ContentControl because the content is always text. Instead it has a Text property that lets you set an initial string or obtain the string that the user typed.
Because TextBox derives from Control, you can specify the background and foreground brushes used in the control, as well as the font. However, at any time, all the text that appears in a particular TextBox will always be the same color and use the same font. The RichTextBox control lets the program (and the user) apply various character and paragraph formatting to different parts of the text. The difference between TextBox and RichTextBox is the same as the difference between Windows Notepad and Windows WordPad.
By default, a TextBox control allows entry of a single line of text.

By default the TextBox isn't interested in the Enter key. If you set :
Label lbl = new Label();
lbl.Content = "File _name:";
The single-line edit control becomes a multiline edit control and now handles carriage returns.

1 comment: