It looks like the stand text block formatting is done on word boundary, i.e. text delimited by spaces. Is there any way to make a custom block so I can format based on words delimited by other characters, e.g. "|", "[", "]" etc. Also, what is the extent of customisation, is it just fore/back colour of text? I'd like bold, italics etc. also so perhaps my best option is to use a rich text editor.
11 Answers, 1 is accepted
RadTextBoxControl was created because we needed a textbox that can show a formatted block for the RadAutoCompleteBox. And as you have noted every word is a different element whose styles can be changed. If you want to separate the items by other symbol use RadAutoCompleteBox where you can specify the delimiter. You can format each block separately which include ForeColor, BackColor, and Font (size, style, family). If you need different styles within the same block (word) you need to use the RichTextEditor.
I hope this will be useful. Let me know if you have additional questions.
Regards,
Dimitar
Progress Telerik
I thought I'd try with the AutoCompleteBox. Interestingly it works with multiline=true.. however it has other drawbacks for me such as only matching once on each line. I wanted a general purpose autocomplete that would simply match any word being typed, anywhere on the textbox, much like Notepad++. Also, it draws a box around the word with the 'x' to remove it, etc.
Looks like if I want a general purpose autocomplete I'll have to implement it myself.
The AutoCompleteBox is not suitable for such general purpose autocomplete functionality. We can continue to discuss this in the other thread.
Should you have any other questions do not hesitate to ask.
Regards,
Dimitar
Progress Telerik
Hi,
Having a TextBoxControl populated with some text in which the key-word "Click" is designated as being included in Custom Blocks (means, acting as buttons), is there any possibility to find which specific Custom Block was clicked? (in this case we could execute specific code for each Custom Block individual).
And the second question: is it possible to build a Custom Block with more than one word?
Thanks
Micha
My guess is that you are using the approach described here: Creating custom blocks | RadTextBoxControl. To distinguish the buttons you can use the Tag property to store some specific inforation. For example:
int
count = 0;
private
void
RadTextBoxControl1_CreateTextBlock(
object
sender, CreateTextBlockEventArgs e)
{
if
(e.Text ==
"here"
)
{
e.TextBlock =
new
ButtonTextBlock() { Tag = count++ };
}
}
A single block must contain only one word, however, you can add another element on top of it and show other text:
public
class
ButtonTextBlock : RadButtonElement, ITextBlock
{
private
int
index;
private
int
offset;
LightVisualElement customText =
new
LightVisualElement();
public
ButtonTextBlock()
{
this
.index = 0;
this
.offset = 0;
this
.MaxSize =
new
Size(0, 12);
this
.DisplayStyle = DisplayStyle.None;
customText.DrawText =
true;
customText.Text =
"Custom Text"
;
this.Children.Add(customText);
}
protected
override
Type ThemeEffectiveType
{
get
{
return
typeof
(RadButtonElement);
}
}
public
int
Index
{
get
{
return
this
.index;
}
set
{
this
.index = value;
}
}
public
int
Length
{
get
{
return
1;
}
}
public
int
Offset
{
get
{
return
this
.offset;
}
set
{
this
.offset = value;
}
}
public
RectangleF ControlBoundingRectangle {
get
;
private
set
; }
public
int
GetCharacterIndexFromX(
float
x)
{
RectangleF bounds =
this
.ControlBoundingRectangle;
float
median = bounds.X + bounds.Width / 2;
return
x <= median ? 0 : 1;
}
public
RectangleF GetRectangleFromCharacterIndex(
int
index,
bool
trailEdge)
{
var bounds =
this
.ControlBoundingRectangle;
if
(index == 1)
{
bounds.X = bounds.Right;
bounds.Width = 0;
}
return
bounds;
}
protected
override
void
OnClick(EventArgs e)
{
base
.OnClick(e);
RadMessageBox.Show(
"Button: "
+
this
.Tag,
"Message"
);
}
}
I hope this will be useful.
Regards,
Dimitar
Progress Telerik
Thanks Dimitar for both answers.
Unfortunately, the first one rose for me more problems/questions than solving the old one. And this because I don't know how to get back the tag's values attached as in your example.I would really appreciated a very short example (if possible in VB - assigning tags to textblocks and retrieving them. And all these actions having the restrictions of the approach described at https://docs.telerik.com/devtools/winforms/editors/textboxcontrol/creating-custom-blocks (means, the TextBlock are created in the TextBoxControl in a separated VB class, in which we retrieve also the Click Event)
Additionally, what are the "m_index" and "offset" properties defined in this class? (what's the exact meaning of "the index of the block"???)
Once again, thanks in advance
Micha
I have attached the desired example. I have added a code for handling the click from the form's class.
In addition, the specified properties are required by our internal logic and are coming from the ITextBlock interface.
I hope this will be useful.
Regards,
Dimitar
Progress Telerik
Hi Dimitar,
Working like a charm!
Many thanks.
If you don't mind, a new question: (hopefully will be the last one......at least that's what I hope :-) Is there any (easy and rapid) possibility to change the look of the text block? (font color, textblock background color, etc, in order to add some more contrast between the textblock and the other text inside the text box?
Mihaela
You can customize the custom blocks directly in the text block class. For example:
'ButtonTextBlock class
Public
Sub
New
()
Me
.index_ = 0
Me
.offset_ = 0
Me
.MaxSize =
New
Size(0, 12)
Me
.DisplayStyle = DisplayStyle.None
customText.ShouldHandleMouseInput =
False
customText.NotifyParentOnMouseInput =
True
customText.DrawText =
True
customText.Text =
"Custom Text"
Me
.ButtonFillElement.BackColor = Color.Red
Me
.ButtonFillElement.GradientStyle = GradientStyles.Solid
Me
.Children.Add(customText)
End
Sub
Should you have any other questions do not hesitate to ask.
Regards,
Dimitar
Progress Telerik