I want to let the user to color some words or phrases in a Textbox.
I thought the features of RadTextBoxControl would be good for that. (In between RadTextBox and RichTextEditor)
First handicap, I seem to have no influence on Block Creation, meaning on how the text is split into Blocks.
Than I assign a text like 'Dvoraks "New World" Symphony'
I get Blocks like
- Dvoraks
- "New
- World"
- Symphony
Not really what I wanted.
I found no other way than this:
radTextBoxControl1.TextBoxElement.ViewElement.Children.Add(
new
TextBlockElement() {Text =
"Dvoraks"
});
radTextBoxControl1.TextBoxElement.ViewElement.Children.Add(
new
TextBlockElement() {Text =
"\"New World\""
});
radTextBoxControl1.TextBoxElement.ViewElement.Children.Add(
new
TextBlockElement() {Text =
"Symphony"
});
Is this a good way, the recommanded way, to do custom splitting ?
Next: I could not attach a click event to a text block.
I found your Demo with a Button inside a TextBox (implementing ITextBlock on RadButtonElement) this works fine.
But something like this, is just never called (replacing the "new TextBoxElement" with "new TBE" in the above snippet of course)
public class TBE : TextBlockElement
{
protected override void OnClick(EventArgs e)
{
base.OnClick(e);
}
}
Than I tried to subscribe to the Click-Event directly. (The Click Event of the TextBlockElement). No catched event either.
Another try:
radTextBoxControl1.TextBoxElement.MouseDown += TextBoxElement_MouseDown;
private void TextBoxElement_MouseDown(object sender, MouseEventArgs e)
{
var clickedElement = radTextBoxControl1.ElementTree.GetElementAtPoint(e.Location) as ITextBlock;
if (clickedElement != null)
{
}
}
No success either: The GetElementAtPoint always returns the TextBoxElement, which is not wrong, but I want a children of it, a TextBlock.
So I need help on how to catch a click on a TextBlock,... than finally I can color my Block on user click (with setting textblock.ForeColor = Red f.e.).
Finally, what I'am missing also is Selecting a TextBlock. The Select Functions of TextBoxControl are all character based.
But has the TextBlock information about it's own position in the whole Text ? Is this the Offset/Length Property ? Documentation don't gives me any clue, if this is something measured in pixel, number of characters, or whatever.
So how do I something like textBoxControl1.Select(textblock) ?