-1

At the start of the application, a form must appear with two buttons on it. On the top button, the text “Contact No.” must be written and on the bottom button the text “Location” must be written. The two buttons must be perfectly center aligned (both horizontally and vertically) in the client area of the form as shown in the screen short below:

enter image description here

When the button with text “Contact No.” is clicked first time, its text must change to your cell no. Please see the screen shot below:

enter image description here

When this button is clicked second time, its text must change to your PTCL no. When this button is clicked third time, its text must change again to your cell no. On clicking the button fourth time the text must change to your PTCL no. and so on.

Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
New Bie
  • 9
  • 1
  • 1
  • Welcome to [so]. You need to tell us what the question is? Stating how you want the application to behave isn't a good fit for this site, please read the [FAQ]'s and [ask]. – Jeremy Thompson Nov 19 '16 at 06:01
  • I think OP wants us to write a program which will do all that mentioned stuff. – mmushtaq Nov 19 '16 at 06:19
  • Is this a question or specification? If this is a question then what is the question? – Fabio Nov 19 '16 at 06:30

2 Answers2

3

For aligning buttons "perfectly" in the center:

  1. Open designer with empty form
  2. Add TableLayoutPanel to the form from ToolBox
  3. Make TableLayoutPanel to have one column and two rows, rows height must be 50% - so panel will have two cells
  4. Set TableLayoutPanel.Dock = Fill
  5. Add a button to the first cell
  6. Add button to the second cell Next steps do for every button
  7. Set Anchor = Bottom for the button in first row
  8. Set Anchor = Top for the button in second row
  9. Set AutoSize = True
  10. Set AutoSizeMode = GrowAndShrink
Fabio
  • 31,528
  • 4
  • 33
  • 72
  • 1
    The answer needs a small correction. The `Anchor` property for top button should be set to `Bottom` and for the bottom button, it should be set to `Top`. Most users are not aware of [such functionality](http://stackoverflow.com/a/39047133/3110834) in TableLayoutPanel. – Reza Aghaei Nov 19 '16 at 13:30
  • Also it would be better if you use a single cell which hosts a FlowLayoutPanel for such requirement. Then you can keep as many buttons as you want in center and control follow direction to align buttons vertically or horizontally and keep the group at center of form. Currently your solution works for 2 buttons. Take a look at [this post](http://stackoverflow.com/a/38824845/3110834) for example. – Reza Aghaei Nov 19 '16 at 13:32
  • @RezaAghaei, thanks - fixed Anchor value for buttons. Agree that `FlowLayoutPanel` provide possibility to dynamically add/remove buttons. My solution was only to satisfy OP requirements. – Fabio Nov 19 '16 at 15:11
0

1.Right-click the toolbar

2.Click Customize...

3.Select the Commands tab

4.Select the Toolbar radio button and select Layout from the dropdown

5.Click Add Command... and select Format from the Categories section

6.Select the Center Horizontally and Center Vertically commands (not Center Horizontal and Center Vertical)


For only one control, you can use Format => Center in Form => Horizontally/Vertically

Vishwa Ratna
  • 5,567
  • 5
  • 33
  • 55
  • It doesn't keep controls at center when the size changes. Take a look at [this post](http://stackoverflow.com/a/38824845/3110834) for example and follow instructions. The `TableLayoutPanel` should be docked to fill the form and should contains only one cell. An auto-size grow and shrink FlowLayoutPanel which its Anchor is set to `None` should be used to host buttons. Put the flow layout in the single cell table layout panel. – Reza Aghaei Nov 19 '16 at 13:39