Winform uses buttons and listview to implement navigation menus similar to QQ settings.
DockStyle is mainly used.
The specific code is as follows:
(Note) Pay special attention to the order in which controls are created.
The order in which controls are created is as follows (in. Design. cs ):
[Csharp]
This. groupBox1 = new System. Windows. Forms. GroupBox ();
This. button1 = new System. Windows. Forms. Button ();
This. button2 = new System. Windows. Forms. Button ();
This. button3 = new System. Windows. Forms. Button ();
This. button4 = new System. Windows. Forms. Button ();
This. button5 = new System. Windows. Forms. Button ();
This. button6 = new System. Windows. Forms. Button ();
This. listView1 = new System. Windows. Forms. ListView ();
The main code is as follows:
// Use listview and six buttons to implement navigation menu functions | Yes
[Csharp]
Private void button#click (object sender, EventArgs e)
{
ResetButton (); // reset button
ListView1. Dock = DockStyle. None;
Button2. Dock = DockStyle. Bottom;
Button3. Dock = DockStyle. Bottom;
Button4. Dock = DockStyle. Bottom;
Button5. Dock = DockStyle. Bottom;
Button6. Dock = DockStyle. Bottom;
ListView1. BringToFront ();
ListView1. Dock = DockStyle. Bottom;
ListView1. Clear ();
}
Private void button2_Click (object sender, EventArgs e)
{
ResetButton (); // reset button
ListView1. Dock = DockStyle. None;
Button3. Dock = DockStyle. Bottom;
Button4. Dock = DockStyle. Bottom;
Button5. Dock = DockStyle. Bottom;
Button6. Dock = DockStyle. Bottom;
ListView1. BringToFront ();
ListView1. Dock = DockStyle. Bottom;
ListView1. Clear ();
}
Private void button3_Click (object sender, EventArgs e)
{
ResetButton (); // reset button
ListView1. Dock = DockStyle. None;
Button4. Dock = DockStyle. Bottom;
Button5. Dock = DockStyle. Bottom;
Button6. Dock = DockStyle. Bottom;
ListView1. BringToFront ();
ListView1. Dock = DockStyle. Bottom;
ListView1. Clear ();
}
Private void button4_Click (object sender, EventArgs e)
{
ResetButton (); // reset button
ListView1. Dock = DockStyle. None;
Button5. Dock = DockStyle. Bottom;
Button6. Dock = DockStyle. Bottom;
ListView1. BringToFront ();
ListView1. Dock = DockStyle. Bottom;
ListView1. Clear ();
}
Private void button5_Click (object sender, EventArgs e)
{
ResetButton (); // reset button
ListView1. Dock = DockStyle. None;
Button6. Dock = DockStyle. Bottom;
ListView1. BringToFront ();
ListView1. Dock = DockStyle. Bottom;
ListView1. Clear ();
}
Private void button6_Click (object sender, EventArgs e)
{
ResetButton (); // reset button
}
Public void ResetButton () // initialization settings
{
Button1. Dock = DockStyle. Bottom;
Button2. Dock = DockStyle. Bottom;
Button3. Dock = DockStyle. Bottom;
Button4. Dock = DockStyle. Bottom;
Button5. Dock = DockStyle. Bottom;
Button6. Dock = DockStyle. Bottom;
ListView1. Dock = DockStyle. Bottom;
ListView1. Dock = DockStyle. None;
Button1. Dock = DockStyle. None;
Button2. Dock = DockStyle. None;
Button3. Dock = DockStyle. None;
Button4. Dock = DockStyle. None;
Button5. Dock = DockStyle. None;
Button6. Dock = DockStyle. None;
}
The implementation result is as follows: