Search code examples
c#winformsdevexpress

How to select text in the label control in DevExpress?


Can I select text in the label control in DevExpress?

enter image description here

I need something like this:

enter image description here

Edit

enter image description here

private void AddLayoutItem(LayoutControlGroup group, string name, string description)
        {
            group.AllowHtmlStringInCaption = true;

            LabelControl label = new LabelControl
            {
                Name = Guid.NewGuid().ToString(),
                Text = description,
                Font = new Font("Tahoma", 11),
                Padding = new Padding(25, 0, 0, 0),
                AutoSizeMode = LabelAutoSizeMode.Vertical,

                AllowDrop = true,
                BorderStyle = 0,
                IsAccessible = true
            };
            AddLayoutItem(group, name, label);
        }

Solution

  • LabelControl does not support selection of the displayed text. However, this can be achived through TextEdit, which you can make look like a label, but users are able to select the text. Set it's BorderStyle property to NoBorder and ReadOnly to true.

    Your code would look something like this:

    private void AddLayoutItem(LayoutControlGroup group, string name, string description)
    {
            group.AllowHtmlStringInCaption = true;
    
            var edit = new TextEdit
            {
                Name = Guid.NewGuid().ToString(),
                Text = description,
                Font = new Font("Tahoma", 11)
            };
            edit.Properties.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
            edit.Properties.ReadOnly = true;
            
            AddLayoutItem(group, name, edit);
     }