NMD
NMD

Reputation: 83

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");
    }
}

Upvotes: 0

Views: 2177

Answers (2)

Samuel Slade
Samuel Slade

Reputation: 8613

You don't want to create the container and then set the DockStyle on that container. Instead, you need to set the DockStyle of the UserControl itself.

Upvotes: 0

Connell
Connell

Reputation: 14411

obj needs to be a reference to the instance of your already existing userControl (in your case, the this keyword). You have created a new instead of the Container1 here.

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");
        }
}

Upvotes: 3

Related Questions