[英]i want to dock User Control
I have make user control and inside that user control takes two buttons name dock and close respectively. 我有一个用户控件,该用户控件内部有两个按钮分别叫停靠和关闭。
Now i want to dock my user control to left when i clicks button dock and close my user control when i clicks button close.. 现在,我想在单击按钮停靠时将用户控件停靠在左侧,并在单击按钮关闭时将用户控件关闭。
(i am trying to use by making object of user control but doesnt helps.....) (我试图通过使用户控制的对象来使用,但没有帮助.....)
void button1_Click(object sender, EventArgs e) {
Container1 obj = new Container1();
if (obj.Dock != DockStyle.None) {
obj.Dock = DockStyle.None;
MessageBox.Show("Dockstyle is None");
}
else {
obj.Dock = DockStyle.Left;
MessageBox.Show("Dockstyle is Left");
}
}
obj
needs to be a reference to the instance of your already existing userControl (in your case, the this
keyword). obj
必须是对您已经存在的userControl实例的引用(在您的情况下为this
关键字)。 You have created a new instead of the Container1
here. 您在这里创建了一个新的Container1
而不是Container1
。
private void button1_Click(object sender, EventArgs e)
{
if (this.Dock != DockStyle.None)
{
this.Dock = DockStyle.None;
MessageBox.Show("Dockstyle is None");
}
else
{
this.Dock = DockStyle.Left;
MessageBox.Show("Dockstyle is Left");
}
}
You don't want to create the container and then set the DockStyle
on that container. 您不想创建容器,然后在该容器上设置DockStyle
。 Instead, you need to set the DockStyle
of the UserControl
itself. 相反,您需要设置UserControl
本身的DockStyle
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.