在表单上显示特定的自定义控件(并隐藏其他控件)?

时间:2014-12-01 04:55:48

标签: c#

我有一个名为myControl.cs的控件。它包含一个组框和一个按钮。在我Form1.cs点击按钮时,点击myControl即会创建并以myControl.cs形式显示。它可以多次创建。

我的问题是,当点击myControl.cs时,我想仅显示该特定myControl.cs的按钮而另一个myControl.cs按钮被隐藏,如何实现?

myControl.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Erd_Maker
{
    public partial class myUserControl: UserControl
    {
        Label[] newColumnAdd;
        int ctr = 3;

        public myUserControl()
        {
            InitializeComponent();
            ini();
        }

        public void ini()
        {
            groupBox1.Click += new EventHandler(groupBox1_Click);
            newColumnAdd = new Label[99];
            this.Size = new System.Drawing.Size(189, 132);
        }

        public override bool AutoSize
        {
            get
            {
                return base.AutoSize;
            }
            set
            {
                base.AutoSize = value;
            }
        }

        public string tableNameText { get; set; }

        public string defaultColumnText { get; set; }

        private void table_Load(object sender, EventArgs e)
        {
            tableName.Text = tableNameText;
            defaultColumn.Text = defaultColumnText;
            groupBox1.Name = tableNameText;
        }

        private void groupBox1_Click(object sender, EventArgs e)
        {
            GroupBox tbl = (GroupBox)sender;
            // This is the event I want to show a button for this control only
            // And the other buttons on the other control will be hidden

        }

    }
}

Form1.cs - >这就是我创建myUserControl的方式

             newTable[tableCounter] = new myUserControl();
             newTable[tableCounter].tableNameText = name;
             newTable[tableCounter].defaultColumnText = column;
             newTable[tableCounter].Name = name;
             newTable[tableCounter].Location = new System.Drawing.Point(tableCounter * 180, 1);
             this.databasePanel.Controls.Add(newTable[tableCounter]);
             newTable[tableCounter].Show();

我无法发布图片,请看这个.. More explanation

0 个答案:

没有答案