Hi :
dose your visual component means a user control?
I suggest you put visiable property into the constructor of this component.
like follow
Code Snippet
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Text;
System.Windows.Forms;
Test2
public partial class MyTextBoxAndButton :Panel
{
private TextBox TB = new TextBox();
private Button BT = new Button();
public MyTextBoxAndButton()
{
this.TB.Visible = false;
this.Width = 200;
this.Height =this.TB.Height;
TB.Width = 150;
this.BT.Width = 50;
this.BT.Height = this.TB.Height;
TB.Location = new Point(this.Location.X, this.Location.Y);
BT.Location = new Point(this.Location.X + this.TB.Width, this.Location.Y);
this.Controls.Add(TB);
this.Controls.Add(BT);
this.BT.Click += new EventHandler(BT_Click);
InitializeComponent();
}
void BT_Click(object sender, EventArgs e)
{
MessageBox.Show("Click");
this.TB.Visible = true;
}
}
|