-1

I have a Windows Forms application with a panel containing six buttons. The buttons are Home, Purchase, Company, Products, Inventory and Customers. I need the exact order of the buttons from top to buttom as tell the names in order. But when I dock the buttons to top the Home button go to second position and the Purchase button go to 1st at the topmost position and other buttons also change its position automatically. I don't need this, I need the Home button at topmost the Purchase at second and Company at third, Products then inventory and the customers. Why is the order of the buttons changing automatically?

What is the best way to dock the buttons in the specific order that I want? Is there a way to achieve this without relying on the default order of the buttons in the panel? Any suggestions or guidance would be greatly appreciated.

I am using Microsoft Visual Studio 2019 community version.

I re-add the buttons to the panel but it didn't work. The buttons are automatically changing its position after I dock them to top of the panel.

Here are the images before dock and after dock:

before dock

after dock

IVSoftware
  • 5,732
  • 2
  • 12
  • 23
  • When you dock Controls, `SendToBack` gives more priority (lowest z-order), the opposite `BringToFront`. You can also use a TableLayoutPanel or a FlowLayoutPanel -- Anchoring instead of docking is also an option. In this case, the z-order doesn't matter – Jimi Mar 18 '23 at 16:00
  • A few note here: [How can I keep a Status Bar from covering my RichTextBox?](https://stackoverflow.com/a/58469851/7444103) – Jimi Mar 18 '23 at 16:02
  • You're saying that you are docking the buttons in the panel. I know you have a good reason for doing that, but can you say what it is? Looking at the screenshots, I would think if anything was going to get docked it would be the container panel that holds the buttons. But maybe it would be clearer if you could [**Edit**](https://stackoverflow.com/posts/75776794/edit) your post and show how you want it to look while the app is actually running. (A simple mock-up done in MS Paint would suffice.) – IVSoftware Mar 18 '23 at 21:27
  • I already docked the panel to the left of my main container As you can see in the Blue background. Then I take second container which is in the middle of the docked one that has the buttons. This is a simple shop management software and the left buttons that I wanted to dock is actually the tabs on which when I click, the user control forms changes. – Asad Faraz Mar 20 '23 at 01:36

1 Answers1

0

You can use a table layout panel which Dock is DockStyle.Top where you add 6 rows and 1 cell and put in there your buttons with the Dock=DockStyle.Fill.

OR

You can add the buttons to the control list in the specific order and set the Dock to DockStyle.Top.

chris
  • 26
  • 3