在ToolBar控件里有多个用户按钮,想点击按钮时,在Panel里显示用户控件出现问题
点击tbarUser按钮时,在Panel里可以显示到UserU用户控件!但是再点击tbarClient按钮或tbarFinance按钮时就没反应啦!那是为什么呢?请高手帮助!
程序里的ToolStrip_Click事件是这样写的:
private void toolBar1_ButtonClick(object sender, ToolBarButtonClickEventArgs e)
{
UserU user = new UserU();
ClientU client = new ClientU();
FinanceU finance = new FinanceU();
if (e.Button == tbarUser)
{
this.pictureBox1.Visible = false;
user.Dock = DockStyle.Fill;
user.Visible = true;
this.panel1.Controls.Add(user);
}
else if (e.Button == tbarClient)
{
client.Dock = DockStyle.Fill;
client.Visible = true;
this.panel1.Controls.Add(client);
}
else if (e.Button == tbarFinance)
{
finance.Dock = DockStyle.Fill;
finance.Visible = true;
this.panel1.Controls.Add(finance);
}
}
点击tbarUser按钮时,在Panel里可以显示到UserU用户控件!但是再点击tbarClient按钮或tbarFinance按钮时就没反应啦!那是为什么呢?请高手帮助!
程序里的ToolStrip_Click事件是这样写的:
private void toolBar1_ButtonClick(object sender, ToolBarButtonClickEventArgs e)
{
UserU user = new UserU();
ClientU client = new ClientU();
FinanceU finance = new FinanceU();
if (e.Button == tbarUser)
{
this.pictureBox1.Visible = false;
user.Dock = DockStyle.Fill;
user.Visible = true;
this.panel1.Controls.Add(user);
}
else if (e.Button == tbarClient)
{
client.Dock = DockStyle.Fill;
client.Visible = true;
this.panel1.Controls.Add(client);
}
else if (e.Button == tbarFinance)
{
finance.Dock = DockStyle.Fill;
finance.Visible = true;
this.panel1.Controls.Add(finance);
}
}
应当把另外的两个控件 如果已经实例化了 Visible = false;掉
还有就是,我已经有用户控件实例化了,还把用户控件的Visilbe=false;还是不行!那我应该怎么做呢?
把Panel里的用户控件先Clear()掉!然后再把别的用户控件加载到Panel里!
this.Controls.GetChildIndex(control);如下设置显示顺序:
this.Controls.SetChildIndex(control, index)index为-1时控件为最上层。