Tải bản đầy đủ - 0 (trang)
17-10. Get Rich Text Input from a User

17-10. Get Rich Text Input from a User

Tải bản đầy đủ - 0trang

CHAPTER 17 ■ WINDOWS PRESENTATION FOUNDATION



You manipulate the content of the FlowDocument by selecting portions of its content using a

System.Windows.Documents.TextSelection object. The TextSelection object contains two properties,

Start and End, which identify the beginning and end positions of the FlowDocument content you want to

manipulate. Once you have a suitable TextSelection object, you can manipulate its content using the

TextSelection members.



■ Note For detailed information about flow content, see the .NET Framework documentation at

http://msdn.microsoft.com/en-us/library/ms753113(VS.100).aspx.



To simplify the manipulation of FlowDocument objects, the RichTextBox supports standard

commands defined by the ApplicationCommands and EditingCommands classes from the

System.Windows.Input namespace. The RichTextBox also supports standard key combinations to execute

basic text-formatting operations such as applying bold, italic, and underline formats to text, as well as

cutting, copying, and pasting selected content. Table 17-3 summarizes some of the more commonly

used members of the RichTextBox control.

Table 17-3. Commonly Used Members of the RichTextBox Control



Member



Summary



Properties

AcceptsTab



Controls whether the user can insert tab characters in the

RichTextBox content or whether pressing Tab takes the user out of the

RichTextBox and moves to the next control marked as a tab stop.



CaretPostion



Gets or sets the current insertion position index of the RichTextBox.



Document



Gets or sets the FlowDocument object that represents the RichTextBox

content.



HorizontalScrollBarVisibility



Determines whether the RichTextBox displays a horizontal scroll bar.



IsReadOnly



Controls whether the RichTextBox is read-only or whether the user

can also edit the content of the TextBox. Even if IsReadOnly is set to

True, you can still programmatically change the content of the

RichTextBox.



Selection



Gets a System.Windows.Documents.TextSelection object representing

the current selection in the RichTextBox.



VerticalScrollBarVisibility



Determines whether the RichTextBox displays a vertical scroll bar.



814



www.it-ebooks.info



CHAPTER 17 ■ WINDOWS PRESENTATION FOUNDATION



Member



Summary



Methods

AppendText



Appends text to the existing content of the RichTextBox.



Copy



Copies the currently selected RichTextBox content to the clipboard.



Cut



Cuts the currently selected RichTextBox content and places it in the

clipboard.



Paste



Pastes the current content of the clipboard over the currently selected

RichTextBox content or inserts it at the cursor position if nothing is

selected.



SelectAll



Selects the entire content of the RichTextBox control.



Undo



Undoes the most recent undoable action on the RichTextBox control.



Events

TextChanged



The event fired when the text in a RichTextBox changes.



The Code

The following code provides a simple example of a RichTextBox used to edit a FlowDocument. The XAML

defines a static FlowDocument that contains a variety of structural and formatting elements. The user

interface provides a set of buttons to manipulate the RichTextBox content. The buttons rely on the

application and editing command support provided by the RichTextBox control and use a style to make

the RichTextBox the target of the button’s command.


xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

Title="Recipe17_10" Height="350" Width="500">













815



www.it-ebooks.info



CHAPTER 17 ■ WINDOWS PRESENTATION FOUNDATION









Layout Tranform















Render Tranform

















819



www.it-ebooks.info



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

17-10. Get Rich Text Input from a User

Tải bản đầy đủ ngay(0 tr)

×