本文介绍了必须复制包含内部控件的GroupBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含一些组合框,文本框和按钮的GroupBox。我想在按钮单击事件上复制此Groupbox。任何帮助将不胜感激。

i have a GroupBox containg some comboboxes, textboxes and a button. I want to duplicate this Groupbox on the button click event. any help would be greatly appreciated.

推荐答案

using System.Windows.Forms;

namespace yourNameSpace
{
    public partial class ucGroupBoxEx : UserControl
    {
        public ucGroupBoxEx()
        {
            InitializeComponent();
        }

        public TextBox TextBox1 { get; private set; }

        private void ucGroupBoxEx_Load(object sender, System.EventArgs e)
        {
            TextBox1 = textBox1;
        }
    }
}

在此代码中,UserControl的加载事件将公共属性'TextBox1设置为当UserControl的实例为时创建的'textBox1的实例创建。注意我们在Property'集合处理程序之前使用了修饰符'private:这是为了确保没有外部方可以更改对内部TextBox的引用。

In this code the UserControl's Load Event sets the Public Property 'TextBox1 to the instance of 'textBox1 created when the an instance of the UserControl is created. Notice we used the modifier 'private before the Property 'set handler: this is to ensure no outside party can change the reference to the internal TextBox.


这篇关于必须复制包含内部控件的GroupBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-18 03:56
查看更多