Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 运行时未设置UI控件的值_C#_Winforms - Fatal编程技术网

C# 运行时未设置UI控件的值

C# 运行时未设置UI控件的值,c#,winforms,C#,Winforms,我有一个基类库,其中包含所有具有扩展功能的UI控件 Ex: XTextBox <---derived from------ TextBox XPanel <---derived from------ Panel XLabel <---derived from------ Label 很多时候,在运行时没有为某些UI控件设置背景色(例如:面板和某些UI控件) 但是,如果我在UI设计器中进行设置,则会设置这些颜色 知道我哪里做错了吗 关于检查外观。GetB

我有一个基类库,其中包含所有具有扩展功能的UI控件

Ex: XTextBox <---derived from------ TextBox
    XPanel   <---derived from------ Panel
    XLabel   <---derived from------ Label
很多时候,在运行时没有为某些UI控件设置背景色(例如:面板和某些UI控件)

但是,如果我在UI设计器中进行设置,则会设置这些颜色

知道我哪里做错了吗


关于

检查外观。GetBackColor()在设置为面板时返回值

BackColor属性是特殊的,它是一个“环境”属性。如果从未分配过,则会自动获取父对象背景色的值。这很好,当您更改窗体的背景色时,它会自动使所有子控件的背景色正确。其他以这种方式表现的属性有前景色、光标和字体

听起来这是你的问题。首先查看属性窗口中颜色不正确的控件的BackColor属性。如果以粗体显示,则右键单击它并选择“重置”。查看InitializeComponent()方法并搜索背景色指定是一种快速找到它们的方法


接下来,检查您的自定义控件是否显式分配BackColor属性。

您究竟在哪里调用该行代码?在加载事件中?检查面板的事件背景颜色已更改
 this.BackColor = CUtility.GetBackColor();
 //this represents the XTextBox control.