Mouhammed Soueidane
Mouhammed Soueidane

Reputation: 1066

Button position according to other buttons' visibility

This might sound like a silly question, but I need to know how to change the position of a button automatically, when other buttons that are right next to it are still not visible. I need to achieve this in Visual Studio 2005 ( I'm using C#).

To give further clarifications on this, let's say that I have three buttons on the top left of a form that I have created. The buttons from right to left are: 1- Back 2- Print 3- Next

Initially, and when the form is first started, only the Next button should be visible, and it should occupy the top right of the screen. Later on, and as the user triggers some events on the screen, the Print and Back buttons should appear, but they should appear on the top right of the form as well, which would achieve the same sequence that I have mentioned above. This same sequence of buttons is a requirement that I need to achieve.

Thanks for the help in advance.

Upvotes: 2

Views: 3966

Answers (2)

roken
roken

Reputation: 4004

You're looking for the FlowLayoutPanel:

http://msdn.microsoft.com/en-us/library/system.windows.forms.flowlayoutpanel.aspx

Set FlowDirection to RightToLeft, add your buttons, and you should be in business.

Upvotes: 6

jordanhill123
jordanhill123

Reputation: 4182

You could use:

Nextbutton.Visible = True; //initially
backbutton.Visible = False; //initially
printbutton.Visible = False; //initially
backbutton.Enabled = False; //initially to prevent tabbing to the control and clicking on it
printbutton.Enabled = False; //initially to prevent tabbing to the control and clicking on it

and then in the event handler(s) set

backbutton.Visible = True;
printbutton.Visible = True;
backbutton.Enabled = True;
printbutton.Enabled = True;

You could even set the location of printButton and backButton initially and they just would not be visible but in the location that you want them to be.

Also, if you need to set the location use:

someButton.Location = //some location on your form and move all three buttons as needed.

If you want them to offset from each other you could even do:

someButton.Location = (otherButton.Location +- /*Some offset*/) ;

Upvotes: 2

Related Questions