编译后,UserControl的文本消失在设计器中

编程入门 行业动态 更新时间:2024-10-09 17:30:21
本文介绍了编译后,UserControl的文本消失在设计器中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的解决方案中发生了最奇怪的事情。 我有一个按钮,它是我自定义的。它继承了UserControl,其文本表示为该控件内的Label。

I have the wierdest thing going on in my solution. I have a button, which I customly made. It inherits UserControl, and its text is represented as a Label inside that control.

自然地,我希望覆盖按钮的文本以设置Label的文本:

Naturally, I wanted the button's text to be overridden to set the Label's text:

或者

/// <summary> /// Gets or sets the text that appears in the button /// </summary> [Category("Appearance"), Description("Gets or sets the text on the button.")] [Browsable(true)] public override string Text { get { return base.Text; } set { base.Text = value; labelButtonText.Text = value; } }

Or

/// <summary> /// Gets or sets the text that appears in the button /// </summary> [Category("Appearance"), Description("Gets or sets the text on the button.")] [Browsable(true)] public override string Text { get { return labelButtonText.Text ; } set { labelButtonText.Text = value; } }

无论使用哪种方法,当我在另一个UserControls / Forms,在编译后消失在设计器中的文本消失。

Regardless of the method, when I use that button in another UserControls/Forms, the text I explicitly put inside in the designer dissappears after compilation.

我在 Button.designer.cs文件中签入,

I checked in the "Button.designer.cs" file, and there is no assignment of the text to null nor empty for neither the UserControl nor the Label.

EDIT :此外,当我将设计器中的文本属性,不会在* .designer.cs文件中设置。

EDIT: Moreover, when I set the Text property in the designer, it does not set in the *.designer.cs file.

预先感谢。

推荐答案

是的,这是设计使然。 UserControl.Text属性如下所示:

Yes, this is by design. The UserControl.Text property looks like this:

[Browsable(false)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] [EditorBrowsable(EditorBrowsableState.Never)] [Bindable(false)] public override string Text { get { return base.Text; } set { base.Text = value; } }

您照顾了[Browsable]属性,但不是 [DesignerSerializationVisibility]。隐藏是使文本消失的原因。通过撤消所有属性来修复它:

You took care of the [Browsable] attribute but not the [DesignerSerializationVisibility]. Hidden is what makes the text disappear. Fix it by undo-ing all of the attributes:

[Browsable(true)] [EditorBrowsable(EditorBrowsableState.Always)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] [Bindable(true)] public override string Text { // etc.. }

更多推荐

编译后,UserControl的文本消失在设计器中

本文发布于:2023-11-11 08:45:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1577929.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:器中   文本   UserControl

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!