Reputation: 4385
I have a panel on my windows forms inside of which I have two text boxes and a button for user login. On successful login i hide the panel and show another button called Process Cases. Everything works the way I want.
myPanel.Visible = false;
btnProcessCases.Visible=true;
The Process Cases button is laid out below the panel. Upon hiding I would like the button to occupy the position that the panel earlier occupied. How do I do that? Right now its positioned below the panel.
Upvotes: 0
Views: 14099
Reputation: 1500
Set the Dock
property of myPanel
to Top then put your button in another panel (buttonPanel) and Dock it to Top. Then toggling the visibility of myPanel
will cause the panel containing the button to nicely slide to the top. No nasty resetting of the physical location of buttons or panels and no nasty design concerns with overlapping controls. The Dock property will soon become your best friend.
Upvotes: 2
Reputation:
btnProcessCases.Location = myPanel.Location;
btnProcessCases.Size = myPanel.Size;
myPanel.Visible = false;
btnProcessCases.Visible=true;
Upvotes: 2
Reputation: 570
Add the following:
btnProcessCases.Left = myPanel.Left;
btnProcessCases.Top = myPanel.Top;
Upvotes: 2
Reputation: 55760
You can just set the Location
property of the button to the location of the myPanel
panel:
btnProcessCases.Location = myPanel.Location;
btnProcessCases.Visible=true;
myPanel.Visible = false;
Upvotes: 1