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 } }