在Windows窗体中添加新的用户控件编程 [英] Adding new user control programmatically in windows forms

查看:157
本文介绍了在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窗体中添加新的用户控件编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆