Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/262.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# 如何修复空白用户控件?_C#_Winforms_User Controls - Fatal编程技术网

C# 如何修复空白用户控件?

C# 如何修复空白用户控件?,c#,winforms,user-controls,C#,Winforms,User Controls,我创建了一个用户控件,其中填充了按钮、标签、文本框等。当我将其添加到FormMain中时,它显示的只是一个150x150的灰色正方形,而不是我的用户控件应该是什么样子。我在这个项目中还有其他用户控件,它们运行得很好。目前没有提供代码,因为基于我的其他用户控件,这应该发生在winforms上——对于这两个UC,我只是从工具箱中拖放 添加其他用户控件之一时发生的情况的图像: 添加所需的userControl时发生的情况的图像: 我的userControl实际外观的图像: 在窗体主设计器中,它们被添加

我创建了一个用户控件,其中填充了按钮、标签、文本框等。当我将其添加到FormMain中时,它显示的只是一个150x150的灰色正方形,而不是我的用户控件应该是什么样子。我在这个项目中还有其他用户控件,它们运行得很好。目前没有提供代码,因为基于我的其他用户控件,这应该发生在winforms上——对于这两个UC,我只是从工具箱中拖放

添加其他用户控件之一时发生的情况的图像:

添加所需的userControl时发生的情况的图像:

我的userControl实际外观的图像:

在窗体主设计器中,它们被添加到此处的选项卡中

this.tabPageTelescope.Controls.Add(this.userControlTelescope21);
this.tabPageTelescope.Controls.Add(this.userControlTelescope1);
后来,它们又出现在这里

// userControlTelescope1
// 
this.userControlTelescope1.Location = new System.Drawing.Point(113, 55);
this.userControlTelescope1.Name = "userControlTelescope1";
this.userControlTelescope1.Size = new System.Drawing.Size(150, 150);
this.userControlTelescope1.TabIndex = 0;
// 
// userControlTelescope21
// 
this.userControlTelescope21.Location = new System.Drawing.Point(236, 13);
this.userControlTelescope21.Name = "userControlTelescope21";
this.userControlTelescope21.Size = new System.Drawing.Size(752, 587);
this.userControlTelescope21.TabIndex = 1;

UserControlScape21和userControl1都是按预期显示的,userControl1是有问题的。除了TabIndex之外,它们具有相同的属性。可能值得注意的是,UserControlCompetale1的大小不是150150-这就是它添加它时的样子。

如果没有代码,我唯一能想到的是确保控件是选项卡窗格的成员,而不是底层窗体。请查看属性面板中的属性或表单设计器的代码。

我遇到了完全相同的问题。一个下午,我把剩下的头发拔了出来,突然意识到我做了一件傻事:

不知怎的,在这个过程中的某个地方,构造函数中对InitializeComponent的调用被删除了


因此,无论是在设计上还是在应用程序运行时,控件都被绘制为一个空白。

您需要提供更多内容。要么是代码,要么是屏幕截图,甚至更好,两者都有。没有这些,似乎不太可能有人能帮助你。诺西奥是对的。我们只能猜测。这可能是用户控件大小的问题。谢谢你们的帮助。我应该在一开始就考虑添加屏幕截图。它们被添加了@Noceo,没有正确显示的userControl实际上比实际显示的小。在选项卡页中是否有其他控件,如空白面板?UserControlCompetale1根据图像看起来大小合适,但位置与代码不匹配。位置8,35应该更靠近左边缘。@LarsTech我不知道。在我添加UserControlCompetale1和UserControlCompetale21之前,选项卡页是空的。我检查了一下,但只是再次检查以确定。代码和图像不是同时拍摄的,因此放置错误。我真傻。很抱歉修好了,嗨,威尔。我刚刚添加了一些代码。据我所知,它们是通过第一段代码添加到选项卡窗格中的。不过,我可能遗漏了一些东西,因为我是C语言的新手。除了TabIndex之外,这些属性是相同的。