简体   繁体   中英

How to create vertical navigation bar in Windows Forms?

在此输入图像描述

Im working on my school project, Windows forms app.

As u see, i create 3 panels, one for header, one for nav bar, and one for content. Can i meake header and nav bar static, like layout in webpages, and change content on btn click.

I do it creating a few panels, and change visibility (true/false) for every panel to show specific one. Is there better whay to do this, i think it has to be more elegant, im beginer, its school project and im finding for clever answer.

Surely there are many options for creating such layout in windows forms. Here I share some good options for Vertical Menu, Center Container and Content Holder.

Vertical Menu

You have many options including these 2 good options:

  • ToolStrip component which its Dock property set to Left . Also items of the menu can have images, and you can set to show images before text or above text. You can make one item checked on click and uncheck other items. This way it's obvious which one is active menu.
  • Panel control containing some RadioButton controls. The Dock property of panel is set to Left and it contains some RadionButton controls which you set its Appearance to Button and its Dock property of them to Top . You can set the FlatAppearance of radio buttons to System or Flat . Also radio buttons can show images before or above text.

Center Container

You can use a Panel as container. Set Dock property of the container panel to Fill .

Content Holder

Like menu, you have many options including these 2 good options:

  • You can use different TabPages of a TabControl as content holders. Put different contents in different tab of the control. You can hide tab headers and also you can disable shortcut keys which makes navigation between tabs. Then it's enough to set selected tab of the control based on selected menu.

  • You can use different Form s as content holders. Put different contents in different forms. Then you can show a form in the content panel based on selected menu. To show a form in content panel, it's enough to set TopLevel property of forms to false and set FormBorderStyle of them to None and the add them to center container controls collection and show the form. You can show and hide forms based on selected menu.

You can Use FlowLayoutPanel instead of Panel and then just add Menu Item blocks to it.

If you give the menu Item proper width considering the FlowLayoutPanel width, you will get the menu you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM