In This Topic
Each root text element (the document itself, header, and footer) has an attached selection object. The selection object defines a set of text elements that are contained in that root that serve as the target for different text operations. The following sections discuss how to work with the selection object.
Obtaining the Selection Object
The text document can contain many document root objects (the document itself) and any header or footer object which is specified per section. The user can edit only one root text element at a time, which is the current editing root of the document. You obtain a reference to that root text element object from the EditingRoot property of the rich text view:
Obtaining a Reference for the Current Selection |
Copy Code
|
NSelection selection = m_RichText.EditingRoot.Selection;
|
Selection Modes
The selection mode can work in three modes. The current selection mode can be obtained from the
Mode property which returns a value from the
ENSelectionMode enum:
Obtaining the Selection Mode |
Copy Code
|
ENSelectionMode selectionMode = selection.Mode;
|
The following table lists the different selection modes:
ENSelectionMode |
Description |
Caret |
In this selection mode, only the position is regarded. |
Range |
In this mode the Anchor/Position fields in the selection form a selected range of text. |
Items |
In this mode the selection contains explicitly selected items. |
The current selection mode is automatically determined based on the operations you perform on the section (you cannot set the selection mode).
Caret Mode
You set the selection in caret mode by calling one of the MoveCaretTo methods of the selection object - for example:
Moving the Caret |
Copy Code
|
selection.MoveCaretTo(new NTextPosition(0, true), false);
|
This line of code will position the caret at the first text position in the root text object the selection is attached to. In order to inspect what is the current caret position you can use the Position property:
Obtaining the Caret Position |
Copy Code
|
NTextPosition caretPosition = selection.Position;
|
It is often useful to be able to move the caret in a specified direction relative to the current caret position. This is performed by all text editing programs when you use the arrow keys, page up, page down etc. In Nevron Text you achieve this by calling the MoveCaret method:
Moving the Caret |
Copy Code
|
selection.MoveCaret(ENCaretMoveDirection.LineBegin, false);
|
The above line of code positiones the caret at the beginning of the current line. The following table lists the values of the ENCaretMoveDirection enum:
ENCaretMoveDirection |
Description |
None |
Caret position does not change. |
PrevLine |
Caret position is moved to the closest position on the previous line. |
NextLine |
Caret position is moved to the closest position on the next line. |
PrevGrapheme |
Caret position is moved to the previous grapheme. |
NextGrapheme |
Caret position is moved to the next grapheme. |
PrevChar |
Caret position is moved to the prev char. |
LineBegin |
Caret position is moved to the beggining of the current line. |
LineEnd |
Caret position is moved to the end of the current line. |
PrevWord |
Caret position is moved to the prev word. |
NextWord |
Caret position is moved to the next word. |
DocumentBegin |
Caret position is moved to the beginning of the document. |
DocumentEnd |
Caret position is moved to the end of the document. |
PrevPage |
Caret position is moved to the previous page. |
NextPage |
Caret position is moved to the next page. |
Range Mode
The selection object automatically enters range mode when you call the MoveCaret method with a second parameter of true or when you explicitly specify a selection range using the SelectRange method. In the first case, the selection extends from the previous caret position to the current caret position, whereas in the second case it is explicitly specified. For example:
Select the First Word |
Copy Code
|
selection.MoveCaretTo(new NTextPosition(0, true), false); selection.MoveCaret(ENCaretMoveDirection.NextWord, true);
|
Select the First 10 characters |
Copy Code
|
selection.SelectRange(new NRangeI(0, 9));
|
Items Mode
The selection object automatically enters items mode when you call the SingleSelect or MultiSelect methods. If you call the first method it will automatically remove previously selected text elements. The second method allows you to select multiple text elements:
Select a Single Paragraph |
Copy Code
|
selection.SingleSelect(paragraph1);
|
Select a Multiple Paragraphs |
Copy Code
|
selection.SingleSelect(paragraph1);
selection.MultiSelect(paragraph2);
|
Note that in the above example the first paragraph is selected using SingleSelect. This will automatically remove previously selected text elements from the selection. The second line of code adds the second paragraph to the list of selected text elements. You can pass any NTextElement derived object to the SingleSelect and MultiSelect methods (including table column).
Deleting Text Content
The selection object has a method called Delete which allows you to delete the currently selected range of text or items. This method has no effect if the selection is in caret mode.
Delete the First 10 Characters |
Copy Code
|
selection.SelectRange(new NRangeI(0, 9)); selection.Delete();
|
When you call the Delete method the selection automatically enters Caret mode.
Inserting Text Content
The selection object has several methods that allow you to insert plain text, tables, images at the current caret position. In general insert methods behave as "delete - insert", meaning that they will delete the currently selected content (if the selection is in Range or Items mode) and then insert the new content at the current caret position.
Inserting Plain Text
Inserting plain text is achieved with the InsertText method - the following example inserts "Hello World" at the beginning of the text root:
Insert "Hello World" |
Copy Code
|
selection.MoveCaretTo(new NTextPosition(0, true), false);
selection.InsertText("Hello World");
|
Inserting Tables
Inserting a table is achieved with the InsertTable method. The first override inserts a blank table if the selection does not contain any text elements (caret mode), or converts the currently selected elements to a table (range and items mode). The following code example shows how to convert the first text characters to a table:
Insert "Hello World" |
Copy Code
|
selection.SelectRange(new NRangeI(0, 9));
selection.InsertTable();
|
Similarly:
Insert "Hello World" |
Copy Code
|
NTable table = new NTable(2, 2); table.Border = NBorder.CreateFilledBorder(NColor.Black); table.BorderThickness = new NMargins(2); selection.InsertTable(table);
|
Inserts a 2x2 table (using delete - insert rule).
Inserting Inlines
You can insert an inline element (text, image, widget) using the InsertAtom method:
Insert "Hello World" |
Copy Code
|
selection.InsertAtom(new NInlineAtom(someInline));
|
Copy / Paste
The selection object allows you to Copy / Paste text content from the clipboard.
Copy
The following example shows how to copy the first ten characters of text to the clipboard:
Copy Text to Clipboard |
Copy Code
|
selection.SelectRange(new NRangeI(0, 9));
selection.Copy();
|
Paste
Similarly paste is performed using the Paste method:
Copy Text to Clipboard |
Copy Code
|
selection.MoveCaretTo(new NTextPosition(0, true), false);
selection.Paste();
|
If you want to paste only plain text then you can use the PasteFromFormat method:
Copy Text to Clipboard |
Copy Code
|
selection.MoveCaretTo(new NTextPosition(0, true), false);
selection.PasteFromFormat("text/plain");
|
In this case the newly inserted text will inherit the formatting (font, font size, font style, filling, background etc.) from the text surrounding the current caret position.
Paste behaves as "delete- insert" meaning that if the selection contains elements (Range or Items mode) they will be deleted. The new content is inserted at the current caret position.
Inline Formatting
The selection method exposes several methods that allow you to apply formatting to the currently selected text inline elements. Those methods work in all selection modes.
Method |
Description |
SetBaseLineToSelectedInlines |
Sets the specified baseline value to the currently selected inlines |
SetStrokeToSelectedInlines |
Sets the specified stroke to the currently selected inlines |
SetFillToSelectedInlines |
Sets the specified fill to the currently selected inlines |
SetBackgroundFillToSelectedInlines |
Sets the specified background fill to the currently selected inlines |
SetHighlightFillToSelectedInlines |
Sets the specified highlight fill to the currently selected inlines |
SetFontNameToSelectedInlines |
Sets the specified font name to the currently selected inlines |
SetFontSizeToSelectedInlines |
Sets the specified font size to the currently selected inlines |
ClearPropetyValueInSelectedInlines |
Clears the specified property from the currently selected inlines |
AddFontStyleToSelectedInlines |
Adds the specified font style to the currently selected inlines |
ClearFontStyleFromSelectedInlines |
Clears the specified font style from the currently selected inlines |
The following code snippet shows how to apply bold formatting to all the inlines in a paragraph:
Copy Text to Clipboard |
Copy Code
|
selection.SelectRange(paragraph1.Range);
selection.AddFontStyleToSelectedInlines(ENFontStyle.Bold);
|
Bullet Formatting
The selection object allows you to apply bullet formatting to the currently selected text. This is achieved by calling the ApplyBullet type method:
Apply Bullet Formatting |
Copy Code
|
selection.SelectRange(paragraph1.Range);
selection.ApplyBulletType(ENBulletListTemplateType.Decimal);
|
Similarly you can also clear bullets from the currently selected text elements using:
Clear Bullet Formatting |
Copy Code
|
selection.ClearBullets();
|
Each root text element (the document itself, header and footer) has an attached selection object. The selection object defines a set of text elements that are contained in that root that serve as the target for different text operations. The following sections discuss how to work with the selection object.
Obtaining the Selection Object
The text document can contain many document root objects (the document itself) and any header or footer object which is specified per section. At each point in time there is only one root object which is the current editing root of the document e.g. the user only modifies one root text element at a time. You obtain a reference to that root object from the EditingRoot property of the rich text view:
Obtaining a Reference for the Current Selection |
Copy Code
|
NSelection selection = m_RichText.EditingRoot.Selection;
|
Selection Modes
The selection mode can work in three modes. The current selection mode can be obtained from the
Mode property which returns a value from the
ENSelectionMode enum:
Obtaining the Selection Mode |
Copy Code
|
ENSelectionMode selectionMode = selection.Mode;
|
The following table lists the different selection modes:
ENSelectionMode |
Description |
Caret |
In this selection mode only the position is regarded. |
Range |
In this mode the Anchor/Position fields in the selection form a selected range of text. |
Items |
In this mode the selection contains explicitly selected items. |
The current selection mode is automatically determined based on the operations you perform on the section (you cannot set the selection mode).
Caret Mode
You set the selection in caret mode by calling one of the MoveCaretTo methods of the selection object - for example:
Moving the Caret |
Copy Code
|
selection.MoveCaretTo(new NTextPosition(0, true), false);
|
This line of code will position the caret at the first text position in the root text object the selection is attached to. In order to inspect what is the current caret position you can use the Position property:
Obtaining the Caret Position |
Copy Code
|
NTextPosition caretPosition = selection.Position;
|
It is often useful to be able to move the caret in a specified direction relative to the current caret position. This is performed by all text editing programs when you use the arrow keys, page up, page down etc. In Nevron Text you achieve this by calling the MoveCaret method:
Moving the Caret |
Copy Code
|
selection.MoveCaret(ENCaretMoveDirection.LineBegin, false);
|
The above line of code positiones the caret at the beginning of the current line. The following table lists the values of the ENCaretMoveDirection enum:
ENCaretMoveDirection |
Description |
None |
Caret position does not change. |
PrevLine |
Caret position is moved to the closest position on the previous line. |
NextLine |
Caret position is moved to the closest position on the next line. |
PrevGrapheme |
Caret position is moved to the previous grapheme. |
NextGrapheme |
Caret position is moved to the next grapheme. |
PrevChar |
Caret position is moved to the prev char. |
LineBegin |
Caret position is moved to the beggining of the current line. |
LineEnd |
Caret position is moved to the end of the current line. |
PrevWord |
Caret position is moved to the prev word. |
NextWord |
Caret position is moved to the next word. |
DocumentBegin |
Caret position is moved to the beginning of the document. |
DocumentEnd |
Caret position is moved to the end of the document. |
PrevPage |
Caret position is moved to the previous page. |
NextPage |
Caret position is moved to the next page. |
Range Mode
The selection object automatically enters range mode when you call the MoveCaret method with a second parameter of true or when you explicitly specify a selection range using the SelectRange method. In the first case the selection extends from the previous caret position to the current caret position, whereas in the second case it is explicitly specified. For example:
Select the First Word |
Copy Code
|
selection.MoveCaretTo(new NTextPosition(0, true), false); selection.MoveCaret(ENCaretMoveDirection.NextWord, true);
|
Select the First 10 characters |
Copy Code
|
selection.SelectRange(new NRangeI(0, 9));
|
Items Mode
The selection object automatically enters items mode when you call the SingleSelect or MultiSelect methods. If you call the first method it will automatically remove previously selected text elements. The second method allows you to select multiple text elements:
Select a Single Paragraph |
Copy Code
|
selection.SingleSelect(paragraph1);
|
Select a Multiple Paragraphs |
Copy Code
|
selection.SingleSelect(paragraph1);
selection.MultiSelect(paragraph2);
|
Note that in the above example the first paragraph is selected using SingleSelect. This will automatically remove previously selected text elements from the selection. The second line of code adds the second paragraph to the list of selected text elements. You can pass any NTextElement derived object to the SingleSelect and MultiSelect methods (including table column).
Deleting Text Content
The selection object has a method called Delete which allows you to delete the currently selected range of text or items. This method has no effect if the selection is in caret mode.
Delete the First 10 Characters |
Copy Code
|
selection.SelectRange(new NRangeI(0, 9)); selection.Delete();
|
When you call the Delete method the selection automatically enters Caret mode.
Inserting Text Content
The selection object has several methods that allow you to insert plain text, tables, images at the current caret position. In general insert methods behave as "delete - insert", meaning that they will delete the currently selected content (if the selection is in Range or Items mode) and then insert the new content at the current caret position.
Inserting Plain Text
Inserting plain text is achieved with the InsertText method - the following example inserts "Hello World" at the beginning of the text root:
Insert "Hello World" |
Copy Code
|
selection.MoveCaretTo(new NTextPosition(0, true), false);
selection.InsertText("Hello World");
|
Inserting Tables
Inserting a table is achieved with the InsertTable method. The first override inserts a blank table if the selection does not contain any text elements (caret mode), or converts the currently selected elements to a table (range and items mode). The following code example shows how to convert the first text characters to a table:
Insert "Hello World" |
Copy Code
|
selection.SelectRange(new NRangeI(0, 9));
selection.InsertTable();
|
Similarly:
Insert "Hello World" |
Copy Code
|
NTable table = new NTable(2, 2); table.Border = NBorder.CreateFilledBorder(NColor.Black); table.BorderThickness = new NMargins(2); selection.InsertTable(table);
|
Inserts a 2x2 table (using delete - insert rule).
Inserting Inlines
You can insert an inline element (text, image, widget) using the InsertAtom method:
Insert "Hello World" |
Copy Code
|
selection.InsertAtom(new NInlineAtom(someInline));
|
Copy / Paste
The selection object allows you to Copy / Paste text content from the clipboard.
Copy
The following example shows how to copy the first ten characters of text to the clipboard:
Copy Text to Clipboard |
Copy Code
|
selection.SelectRange(new NRangeI(0, 9));
selection.Copy();
|
Paste
Similarly paste is performed using the Paste method:
Copy Text to Clipboard |
Copy Code
|
selection.MoveCaretTo(new NTextPosition(0, true), false);
selection.Paste();
|
If you want to paste only plain text then you can use the PasteFromFormat method:
Copy Text to Clipboard |
Copy Code
|
selection.MoveCaretTo(new NTextPosition(0, true), false);
selection.PasteFromFormat("text/plain");
|
In this case the newly inserted text will inherit the formatting (font, font size, font style, filling, background etc.) from the text surrounding the current caret position.
Paste behaves as "delete- insert" meaning that if the selection contains elements (Range or Items mode) they will be deleted. The new content is inserted at the current caret position.
Inline Formatting
The selection method exposes several methods that allow you to apply formatting to the currently selected text inline elements. Those methods work in all selection modes.
Method |
Description |
SetBaseLineToSelectedInlines |
Sets the specified baseline value to the currently selected inlines |
SetStrokeToSelectedInlines |
Sets the specified stroke to the currently selected inlines |
SetFillToSelectedInlines |
Sets the specified fill to the currently selected inlines |
SetBackgroundFillToSelectedInlines |
Sets the specified background fill to the currently selected inlines |
SetHighlightFillToSelectedInlines |
Sets the specified highlight fill to the currently selected inlines |
SetFontNameToSelectedInlines |
Sets the specified font name to the currently selected inlines |
SetFontSizeToSelectedInlines |
Sets the specified font size to the currently selected inlines |
ClearPropetyValueInSelectedInlines |
Clears the specified property from the currently selected inlines |
AddFontStyleToSelectedInlines |
Adds the specified font style to the currently selected inlines |
ClearFontStyleFromSelectedInlines |
Clears the specified font style from the currently selected inlines |
The following code snippet shows how to apply bold formatting to all the inlines in a paragraph:
Copy Text to Clipboard |
Copy Code
|
selection.SelectRange(paragraph1.Range);
selection.AddFontStyleToSelectedInlines(ENFontStyle.Bold);
|
Bullet Formatting
The selection object allows you to apply bullet formatting to the currently selected text. This is achieved by calling the ApplyBullet type method:
Apply Bullet Formatting |
Copy Code
|
selection.SelectRange(paragraph1.Range);
selection.ApplyBulletType(ENBulletListTemplateType.Decimal);
|
Similarly you can also clear bullets from the currently selected text elements using:
Clear Bullet Formatting |
Copy Code
|
selection.ClearBullets();
|
Each root text element (the document itself, header and footer) has an attached selection object. The selection object defines a set of text elements that are contained in that root that serve as the target for different text operations. The following sections discuss how to work with the selection object.
Obtaining the Selection Object
The text document can contain many document root objects (the document itself) and any header or footer object which is specified per section. At each point in time there is only one root object which is the current editing root of the document e.g. the user only modifies one root text element at a time. You obtain a reference to that root object from the EditingRoot property of the rich text view:
Obtaining a Reference for the Current Selection |
Copy Code
|
NSelection selection = m_RichText.EditingRoot.Selection;
|
Selection Modes
The selection mode can work in three modes. The current selection mode can be obtained from the
Mode property which returns a value from the
ENSelectionMode enum:
Obtaining the Selection Mode |
Copy Code
|
ENSelectionMode selectionMode = selection.Mode;
|
The following table lists the different selection modes:
ENSelectionMode |
Description |
Caret |
In this selection mode only the position is regarded. |
Range |
In this mode the Anchor/Position fields in the selection form a selected range of text. |
Items |
In this mode the selection contains explicitly selected items. |
The current selection mode is automatically determined based on the operations you perform on the section (you cannot set the selection mode).
Caret Mode
You set the selection in caret mode by calling one of the MoveCaretTo methods of the selection object - for example:
Moving the Caret |
Copy Code
|
selection.MoveCaretTo(new NTextPosition(0, true), false);
|
This line of code will position the caret at the first text position in the root text object the selection is attached to. In order to inspect what is the current caret position you can use the Position property:
Obtaining the Caret Position |
Copy Code
|
NTextPosition caretPosition = selection.Position;
|
It is often useful to be able to move the caret in a specified direction relative to the current caret position. This is performed by all text editing programs when you use the arrow keys, page up, page down etc. In Nevron Text you achieve this by calling the MoveCaret method:
Moving the Caret |
Copy Code
|
selection.MoveCaret(ENCaretMoveDirection.LineBegin, false);
|
The above line of code positiones the caret at the beginning of the current line. The following table lists the values of the ENCaretMoveDirection enum:
ENCaretMoveDirection |
Description |
None |
Caret position does not change. |
PrevLine |
Caret position is moved to the closest position on the previous line. |
NextLine |
Caret position is moved to the closest position on the next line. |
PrevGrapheme |
Caret position is moved to the previous grapheme. |
NextGrapheme |
Caret position is moved to the next grapheme. |
PrevChar |
Caret position is moved to the prev char. |
LineBegin |
Caret position is moved to the beggining of the current line. |
LineEnd |
Caret position is moved to the end of the current line. |
PrevWord |
Caret position is moved to the prev word. |
NextWord |
Caret position is moved to the next word. |
DocumentBegin |
Caret position is moved to the beginning of the document. |
DocumentEnd |
Caret position is moved to the end of the document. |
PrevPage |
Caret position is moved to the previous page. |
NextPage |
Caret position is moved to the next page. |
Range Mode
The selection object automatically enters range mode when you call the MoveCaret method with a second parameter of true or when you explicitly specify a selection range using the SelectRange method. In the first case the selection extends from the previous caret position to the current caret position, whereas in the second case it is explicitly specified. For example:
Select the First Word |
Copy Code
|
selection.MoveCaretTo(new NTextPosition(0, true), false); selection.MoveCaret(ENCaretMoveDirection.NextWord, true);
|
Select the First 10 characters |
Copy Code
|
selection.SelectRange(new NRangeI(0, 9));
|
Items Mode
The selection object automatically enters items mode when you call the SingleSelect or MultiSelect methods. If you call the first method it will automatically remove previously selected text elements. The second method allows you to select multiple text elements:
Select a Single Paragraph |
Copy Code
|
selection.SingleSelect(paragraph1);
|
Select a Multiple Paragraphs |
Copy Code
|
selection.SingleSelect(paragraph1);
selection.MultiSelect(paragraph2);
|
Note that in the above example the first paragraph is selected using SingleSelect. This will automatically remove previously selected text elements from the selection. The second line of code adds the second paragraph to the list of selected text elements. You can pass any NTextElement derived object to the SingleSelect and MultiSelect methods (including table column).
Deleting Text Content
The selection object has a method called Delete which allows you to delete the currently selected range of text or items. This method has no effect if the selection is in caret mode.
Delete the First 10 Characters |
Copy Code
|
selection.SelectRange(new NRangeI(0, 9)); selection.Delete();
|
When you call the Delete method the selection automatically enters Caret mode.
Inserting Text Content
The selection object has several methods that allow you to insert plain text, tables, images at the current caret position. In general insert methods behave as "delete - insert", meaning that they will delete the currently selected content (if the selection is in Range or Items mode) and then insert the new content at the current caret position.
Inserting Plain Text
Inserting plain text is achieved with the InsertText method - the following example inserts "Hello World" at the beginning of the text root:
Insert "Hello World" |
Copy Code
|
selection.MoveCaretTo(new NTextPosition(0, true), false);
selection.InsertText("Hello World");
|
Inserting Tables
Inserting a table is achieved with the InsertTable method. The first override inserts a blank table if the selection does not contain any text elements (caret mode), or converts the currently selected elements to a table (range and items mode). The following code example shows how to convert the first text characters to a table:
Insert "Hello World" |
Copy Code
|
selection.SelectRange(new NRangeI(0, 9));
selection.InsertTable();
|
Similarly:
Insert "Hello World" |
Copy Code
|
NTable table = new NTable(2, 2); table.Border = NBorder.CreateFilledBorder(NColor.Black); table.BorderThickness = new NMargins(2); selection.InsertTable(table);
|
Inserts a 2x2 table (using delete - insert rule).
Inserting Inlines
You can insert an inline element (text, image, widget) using the InsertAtom method:
Insert "Hello World" |
Copy Code
|
selection.InsertAtom(new NInlineAtom(someInline));
|
Copy / Paste
The selection object allows you to Copy / Paste text content from the clipboard.
Copy
The following example shows how to copy the first ten characters of text to the clipboard:
Copy Text to Clipboard |
Copy Code
|
selection.SelectRange(new NRangeI(0, 9));
selection.Copy();
|
Paste
Similarly paste is performed using the Paste method:
Copy Text to Clipboard |
Copy Code
|
selection.MoveCaretTo(new NTextPosition(0, true), false);
selection.Paste();
|
If you want to paste only plain text then you can use the PasteFromFormat method:
Copy Text to Clipboard |
Copy Code
|
selection.MoveCaretTo(new NTextPosition(0, true), false);
selection.PasteFromFormat("text/plain");
|
In this case the newly inserted text will inherit the formatting (font, font size, font style, filling, background etc.) from the text surrounding the current caret position.
Paste behaves as "delete- insert" meaning that if the selection contains elements (Range or Items mode) they will be deleted. The new content is inserted at the current caret position.
Inline Formatting
The selection method exposes several methods that allow you to apply formatting to the currently selected text inline elements. Those methods work in all selection modes.
Method |
Description |
SetBaseLineToSelectedInlines |
Sets the specified baseline value to the currently selected inlines |
SetStrokeToSelectedInlines |
Sets the specified stroke to the currently selected inlines |
SetFillToSelectedInlines |
Sets the specified fill to the currently selected inlines |
SetBackgroundFillToSelectedInlines |
Sets the specified background fill to the currently selected inlines |
SetHighlightFillToSelectedInlines |
Sets the specified highlight fill to the currently selected inlines |
SetFontNameToSelectedInlines |
Sets the specified font name to the currently selected inlines |
SetFontSizeToSelectedInlines |
Sets the specified font size to the currently selected inlines |
ClearPropetyValueInSelectedInlines |
Clears the specified property from the currently selected inlines |
AddFontStyleToSelectedInlines |
Adds the specified font style to the currently selected inlines |
ClearFontStyleFromSelectedInlines |
Clears the specified font style from the currently selected inlines |
The following code snippet shows how to apply bold formatting to all the inlines in a paragraph:
Copy Text to Clipboard |
Copy Code
|
selection.SelectRange(paragraph1.Range);
selection.AddFontStyleToSelectedInlines(ENFontStyle.Bold);
|
Bullet Formatting
The selection object allows you to apply bullet formatting to the currently selected text. This is achieved by calling the ApplyBullet type method:
Apply Bullet Formatting |
Copy Code
|
selection.SelectRange(paragraph1.Range);
selection.ApplyBulletType(ENBulletListTemplateType.Decimal);
|
Similarly you can also clear bullets from the currently selected text elements using:
Clear Bullet Formatting |
Copy Code
|
selection.ClearBullets();
|
At each point in time there is only one root object which is the current editing root of the document e.g. the user only modifies one root text element at a time. You obtain a reference to that root object from the EditingRoot property of the rich text view:
Obtaining a Reference for the Current Selection |
Copy Code
|
NSelection selection = m_RichText.EditingRoot.Selection;
|
Selection Modes
The selection mode can work in three modes. The current selection mode can be obtained from the
Mode property which returns a value from the
ENSelectionMode enum:
Obtaining the Selection Mode |
Copy Code
|
ENSelectionMode selectionMode = selection.Mode;
|
The following table lists the different selection modes:
ENSelectionMode |
Description |
Caret |
In this selection mode only the position is regarded. |
Range |
In this mode the Anchor/Position fields in the selection form a selected range of text. |
Items |
In this mode the selection contains explicitly selected items. |
The current selection mode is automatically determined based on the operations you perform on the section (you cannot set the selection mode).
Caret Mode
You set the selection in caret mode by calling one of the MoveCaretTo methods of the selection object - for example:
Moving the Caret |
Copy Code
|
selection.MoveCaretTo(new NTextPosition(0, true), false);
|
This line of code will position the caret at the first text position in the root text object the selection is attached to. In order to inspect what is the current caret position you can use the Position property:
Obtaining the Caret Position |
Copy Code
|
NTextPosition caretPosition = selection.Position;
|
It is often useful to be able to move the caret in a specified direction relative to the current caret position. This is performed by all text editing programs when you use the arrow keys, page up, page down etc. In Nevron Text you achieve this by calling the MoveCaret method:
Moving the Caret |
Copy Code
|
selection.MoveCaret(ENCaretMoveDirection.LineBegin, false);
|
The above line of code positiones the caret at the beginning of the current line. The following table lists the values of the ENCaretMoveDirection enum:
ENCaretMoveDirection |
Description |
None |
Caret position does not change. |
PrevLine |
Caret position is moved to the closest position on the previous line. |
NextLine |
Caret position is moved to the closest position on the next line. |
PrevGrapheme |
Caret position is moved to the previous grapheme. |
NextGrapheme |
Caret position is moved to the next grapheme. |
PrevChar |
Caret position is moved to the prev char. |
LineBegin |
Caret position is moved to the beggining of the current line. |
LineEnd |
Caret position is moved to the end of the current line. |
PrevWord |
Caret position is moved to the prev word. |
NextWord |
Caret position is moved to the next word. |
DocumentBegin |
Caret position is moved to the beginning of the document. |
DocumentEnd |
Caret position is moved to the end of the document. |
PrevPage |
Caret position is moved to the previous page. |
NextPage |
Caret position is moved to the next page. |
Range Mode
The selection object automatically enters range mode when you call the MoveCaret method with a second parameter of true or when you explicitly specify a selection range using the SelectRange method. In the first case the selection extends from the previous caret position to the current caret position, whereas in the second case it is explicitly specified. For example:
Select the First Word |
Copy Code
|
selection.MoveCaretTo(new NTextPosition(0, true), false); selection.MoveCaret(ENCaretMoveDirection.NextWord, true);
|
Select the First 10 characters |
Copy Code
|
selection.SelectRange(new NRangeI(0, 9));
|
Items Mode
The selection object automatically enters items mode when you call the SingleSelect or MultiSelect methods. If you call the first method it will automatically remove previously selected text elements. The second method allows you to select multiple text elements:
Select a Single Paragraph |
Copy Code
|
selection.SingleSelect(paragraph1);
|
Select a Multiple Paragraphs |
Copy Code
|
selection.SingleSelect(paragraph1);
selection.MultiSelect(paragraph2);
|
Note that in the above example the first paragraph is selected using SingleSelect. This will automatically remove previously selected text elements from the selection. The second line of code adds the second paragraph to the list of selected text elements. You can pass any NTextElement derived object to the SingleSelect and MultiSelect methods (including table column).
Deleting Text Content
The selection object has a method called Delete which allows you to delete the currently selected range of text or items. This method has no effect if the selection is in caret mode.
Delete the First 10 Characters |
Copy Code
|
selection.SelectRange(new NRangeI(0, 9)); selection.Delete();
|
When you call the Delete method the selection automatically enters Caret mode.
Inserting Text Content
The selection object has several methods that allow you to insert plain text, tables, images at the current caret position. In general insert methods behave as "delete - insert", meaning that they will delete the currently selected content (if the selection is in Range or Items mode) and then insert the new content at the current caret position.
Inserting Plain Text
Inserting plain text is achieved with the InsertText method - the following example inserts "Hello World" at the beginning of the text root:
Insert "Hello World" |
Copy Code
|
selection.MoveCaretTo(new NTextPosition(0, true), false);
selection.InsertText("Hello World");
|
Inserting Tables
Inserting a table is achieved with the InsertTable method. The first override inserts a blank table if the selection does not contain any text elements (caret mode), or converts the currently selected elements to a table (range and items mode). The following code example shows how to convert the first text characters to a table:
Insert "Hello World" |
Copy Code
|
selection.SelectRange(new NRangeI(0, 9));
selection.InsertTable();
|
Similarly:
Insert "Hello World" |
Copy Code
|
NTable table = new NTable(2, 2); table.Border = NBorder.CreateFilledBorder(NColor.Black); table.BorderThickness = new NMargins(2); selection.InsertTable(table);
|
Inserts a 2x2 table (using delete - insert rule).
Inserting Inlines
You can insert an inline element (text, image, widget) using the InsertAtom method:
Insert "Hello World" |
Copy Code
|
selection.InsertAtom(new NInlineAtom(someInline));
|
Copy / Paste
The selection object allows you to Copy / Paste text content from the clipboard.
Copy
The following example shows how to copy the first ten characters of text to the clipboard:
Copy Text to Clipboard |
Copy Code
|
selection.SelectRange(new NRangeI(0, 9));
selection.Copy();
|
Paste
Similarly paste is performed using the Paste method:
Copy Text to Clipboard |
Copy Code
|
selection.MoveCaretTo(new NTextPosition(0, true), false);
selection.Paste();
|
If you want to paste only plain text then you can use the PasteFromFormat method:
Copy Text to Clipboard |
Copy Code
|
selection.MoveCaretTo(new NTextPosition(0, true), false);
selection.PasteFromFormat("text/plain");
|
In this case the newly inserted text will inherit the formatting (font, font size, font style, filling, background etc.) from the text surrounding the current caret position.
Paste behaves as "delete- insert" meaning that if the selection contains elements (Range or Items mode) they will be deleted. The new content is inserted at the current caret position.
Inline Formatting
The selection method exposes several methods that allow you to apply formatting to the currently selected text inline elements. Those methods work in all selection modes.
Method |
Description |
SetBaseLineToSelectedInlines |
Sets the specified baseline value to the currently selected inlines |
SetStrokeToSelectedInlines |
Sets the specified stroke to the currently selected inlines |
SetFillToSelectedInlines |
Sets the specified fill to the currently selected inlines |
SetBackgroundFillToSelectedInlines |
Sets the specified background fill to the currently selected inlines |
SetHighlightFillToSelectedInlines |
Sets the specified highlight fill to the currently selected inlines |
SetFontNameToSelectedInlines |
Sets the specified font name to the currently selected inlines |
SetFontSizeToSelectedInlines |
Sets the specified font size to the currently selected inlines |
ClearPropetyValueInSelectedInlines |
Clears the specified property from the currently selected inlines |
AddFontStyleToSelectedInlines |
Adds the specified font style to the currently selected inlines |
ClearFontStyleFromSelectedInlines |
Clears the specified font style from the currently selected inlines |
The following code snippet shows how to apply bold formatting to all the inlines in a paragraph:
Copy Text to Clipboard |
Copy Code
|
selection.SelectRange(paragraph1.Range);
selection.AddFontStyleToSelectedInlines(ENFontStyle.Bold);
|
Bullet Formatting
The selection object allows you to apply bullet formatting to the currently selected text. This is achieved by calling the ApplyBullet type method:
Apply Bullet Formatting |
Copy Code
|
selection.SelectRange(paragraph1.Range);
selection.ApplyBulletType(ENBulletListTemplateType.Decimal);
|
Similarly you can also clear bullets from the currently selected text elements using:
Clear Bullet Formatting |
Copy Code
|
selection.ClearBullets();
|
See Also