【问题标题】:How to select text in the label control in DevExpress?如何在 DevExpress 的标签控件中选择文本?
【发布时间】:2020-07-29 07:58:57
【问题描述】:

我可以在 DevExpress 的标签控件中选择文本吗?

我需要这样的东西:

编辑

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);
        }

【问题讨论】:

  • 您使用哪个组件来显示文本?
  • @MarkoJuvančič 是布局控件,添加截图
  • 我的意思是显示文本的组件。例如,哪个类型的组件显示“IT Direktor”?
  • @MarkoJuvančič 它是 LabelControl。我尝试添加 AllowDrop、BorderStyle 和 IsAccessible,但它不起作用。添加代码
  • 这就是您无法选择文本的原因。使用TextEdit 并将其BorderStyle 属性设置为NoBorder 并将ReadOnly 设置为true

标签: c# winforms devexpress


【解决方案1】:

LabelControl 不支持选择显示的文本。 但是,这可以通过TextEdit 来实现,您可以使它看起来像一个标签,但用户可以选择文本。将其 BorderStyle 属性设置为 NoBorder 并将 ReadOnly 设置为 true。

您的代码将如下所示:

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);
 }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-27
    • 1970-01-01
    • 1970-01-01
    • 2020-06-17
    • 2022-01-20
    • 2020-01-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多