This is a migrated thread and some comments may be shown as answers.

RadTextBoxControl custom block

11 Answers 42 Views
TextBoxControl
This is a migrated thread and some comments may be shown as answers.
Tino
Top achievements
Rank 1
Tino asked on 12 Feb 2018, 04:29 AM

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

Sort by
0
Accepted
Dimitar
Telerik team
answered on 12 Feb 2018, 11:18 AM
Hi Tino,

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
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Tino
Top achievements
Rank 1
answered on 12 Feb 2018, 09:17 PM
ok thanks
0
Tino
Top achievements
Rank 1
answered on 12 Feb 2018, 09:27 PM

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.

0
Tino
Top achievements
Rank 1
answered on 12 Feb 2018, 09:54 PM
Sorry... posted into the wrong thread. Please move if possible.
0
Dimitar
Telerik team
answered on 13 Feb 2018, 12:50 PM
Hello Tino,

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
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Mihaela
Top achievements
Rank 1
answered on 12 Jul 2018, 01:44 PM

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

0
Dimitar
Telerik team
answered on 13 Jul 2018, 09:42 AM
Hi Mihaela,

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
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Mihaela
Top achievements
Rank 1
answered on 17 Jul 2018, 05:34 PM

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

0
Dimitar
Telerik team
answered on 18 Jul 2018, 10:51 AM
Hi Mihaela,

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
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Mihaela
Top achievements
Rank 1
answered on 26 Jul 2018, 04:11 PM

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

0
Dimitar
Telerik team
answered on 27 Jul 2018, 08:03 AM
Hello 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
Get quickly and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
TextBoxControl
Asked by
Tino
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Tino
Top achievements
Rank 1
Mihaela
Top achievements
Rank 1
Share this question
or