Adding new user control programmatically in windows forms(在 Windows 窗体中以编程方式添加新的用户控件)
问题描述
嘿,首先我想指出,我知道这里还有关于这个话题的其他几个问题,我什至自己以前也做过这件事.我在这里问是因为我不知道我的问题是什么.
Hey so first off i would like to point out that I know that there are several other questions about this topic up here, I have even done this exact thing myself before. I am asking on here because I do not know what my problem is.
这是我尝试显示新用户控件的代码
Here is the code where I attempt to display the new user control
private void ValidationLabel_Click(object sender, EventArgs e)
{
EntrySuggestion t_ES = new EntrySuggestion();
t_ES.Show();
MainScreen home = new MainScreen();
home.Show();
}
我试图让 t_ES 显示(它没有),但主屏幕可以.这两个都是用户控件.
I was trying to get the t_ES to display (which it does not) but the main Screen does. Both of these are User Controls.
这是我的 EntrySuggestion 用户控件的代码
Here is the code for my EntrySuggestion User control
using System;
using System.Collections;
using System.Windows.Forms;
namespace TeamManagementSystem
{
public partial class EntrySuggestion : UserControl
{
private ArrayList items = new ArrayList();
public EntrySuggestion()
{
InitializeComponent();
}
public EntrySuggestion(ArrayList i)
{
InitializeComponent();
items = (ArrayList)i.Clone();
}
private void EntrySuggestion_Load(object sender, EventArgs e)
{
foreach (string item in items)
{
RadioButton t_RB = new RadioButton();
t_RB.Text = item;
ItemSuggestionTable.Controls.Add(t_RB);
}
}
}
}
我确实想使用第二个构造函数,但我也无法使用它.任何帮助都会很棒
I do want to use the second constructor but I cannot get this to work with either. Any help would be great
推荐答案
您需要将您的用户控件添加到主窗体(或已存在的另一个容器)的显示表面
You need to add your user control to the display surface of the main form (or another container already present)
MainScreen home = new MainScreen();
home.Show();
EntrySuggestion t_ES = new EntrySuggestion();
home.Controls.Add(t_ES);
这篇关于在 Windows 窗体中以编程方式添加新的用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Windows 窗体中以编程方式添加新的用户控件
基础教程推荐
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30