我有一个名为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