Home > Net >  A few lines of code with c # drawer navigation menu
A few lines of code with c # drawer navigation menu

Time:11-26

Amateur FoxPro learned for several years, never contact with c #, this several days on a whim, want to make a drawer in the c # navigation menu, but dazed by control attributes of the Dock, after some fumbling finally succeeded, of course, this is just a prototype, beginners can see, also please everybody MoXiao words, and can put forward improvements, thank you!
A, preparation:
1, a panel control, named panel1;
2, the number of a button control, named for the respectively, button2, button3... , all height of 25 ( important! Must be set to the same height! ), TabIndex attribute respectively 0,1,2,3 ( is very important! Must start from 0 sequentially increasing , as to why, you naturally understand behind), adjust the layout, as shown in figure 1:
3, open the form Designer. Cs, from top to bottom to modify as you want to order, such as for button2, button3,... And so on ( is very important! Order from top to bottom to be exactly the same as that of the layout of the figure a, can't reverse , as to why, you look at the controls of the Dock property will understand), as shown in figure 2:



Second, in a button control in the Click event to write down the following code:
Int myHeight=25;//assume that the Button height is 25, can be defined by oneself, but all with demanding
Int myIndex=this. Panel1. Controls. IndexOf ((Button) sender);//get the current control index
Foreach (Control myButton in this. Panel1. Controls)//traverse all Controls
{
If (myButton TabIndex & lt;=myIndex)
{
MyButton. The Dock=DockStyle. None;//remove the Dock first attribute (this step is very important)
MyButton. Top=myButton. TabIndex * myHeight;//to redefine the Top value
}
The else
{
MyButton. The Dock=DockStyle. Bottom;//set the Dock property: down
}
}

CodePudding user response:

Thanks for sharing technology, recommend to you,

CodePudding user response:

reference 1st floor caozhy response:
thanks for sharing technology, to recommend you,

Thank you very much!

CodePudding user response:

CodePudding user response:

C # studious? I also want to into the pit

CodePudding user response:

Such a dish, don't recommend,

CodePudding user response:

Probably like this
 
using System;
Using System. Collections. Generic;
Using System. Drawing;
using System.Windows.Forms;

The namespace Test_1
{
Public partial class Form1: Form
{
Private int select_num=0;

Public class Drawer
{
Public string btn_text;
Public int btn_height;
Public int content_height;
Public Control Control;//place the component inside the
Public the Drawer (string text, int bh, int ch, Control cl)
{
Btn_text=text;
Btn_height=bh.
Content_height=ch;
The control=cl;
}
}
Public static List Drawers=new List (a);

Public void DrawerMenu (Control the parent, Point Point, BorderStyle BorderStyle, Color bcolor, Size Size)
{
The Panel panel_box=new Panel () {Size=Size, BackColor=bcolor};
For (int I=drawers. Count - 1; I> - 1; I -)
{
A Panel panel_control=new Panel () {Dock=DockStyle. Top Name="window_" + I, BackColor=Color. SteelBlue};
Panel_box. Controls. The Add (panel_control);
If (I==0) panel_control. Visible=true;
The else panel_control. Visible=false;
Panel_control. Controls. The Add (drawers [I]. Control);
The Button Button=new Button () {Dock=DockStyle. Top, Height=drawers [I] btn_height, Text=drawers [I] btn_text, Tag=I};
Button. Click +=Button_Click;
Panel_box. Controls. The Add (button);
}
The parent. Controls. The Add (panel_box);
}

Private void Button_Click (object sender, EventArgs e)
{
The Control pL=(Control) sender;
If (select_num!=(int) pL.
Tag){
PL. Parent. Controls [r]. "window_ + select_num" Visible=false;
PL. Parent. Controls [" window_ "+ pL (int). The Tag]. Visible=true;
PL select_num=(int). The Tag;
}
}

Public _click ()
{
InitializeComponent ();

Drawers. The Add (new to the Drawer (" Button_1 ", 25, 35, null));
Drawers. The Add (new to the Drawer (" Button_2 ", 25, 35, null));
Drawers. The Add (new to the Drawer (" Button_3 ", 25, 35, null));
Drawers. The Add (new to the Drawer (" Button_4 ", 25, 35, null));
DrawerMenu (this, new Point (30, 30), BorderStyle. FixedSingle, Color, White, new Size (200, 300));
}
}
}

CodePudding user response:

refer to fifth floor health day line reply:
dishes, so don't recommend,

Friend, any player from rookie, no people are born to understand! I learn c # 3 days, it is the amateur, natural not you very well, the real master is always modest, you never know tomorrow or the day after tomorrow, let you does eye before a few streets rookie will jilt you! If you think that the code is not good, you can write a better to share,

CodePudding user response:

Very good, although I don't c #

CodePudding user response:

Good, I also am amateur study

CodePudding user response:

refer to the eighth floor of ants pig reply:
quite good, although I don't c #


nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • C#
  • Related