Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
when change the dock property of buttons,the order of buttons is changing please help me for re arrange the order.
for example i taken the 3 buttons button 1,button 2,button 3.
i set the following properties

C#
this.button 1.Dock = System.Windows.Forms.DockStyle.Bottom;
 this.button 2.Dock = System.Windows.Forms.DockStyle.Bottom;
 this.button 3.Dock = System.Windows.Forms.DockStyle.Bottom;



the output of the above properties is

button 3
button 2
button 1

but i need as

button 1
button 2
button 3

please help me
Posted
Updated 2-Sep-13 23:17pm
v3
Comments
Marvin Ma 3-Sep-13 4:02am    
The relevant part of your code would be nice to see, so we can help you.
johannesnestler 3-Sep-13 10:34am    
No, this is nothing where a TableLayoutPanel makes any sense - I don't say that this control doesn't have a use-case. but for the simple problem of adding the controls in the intuitive (but wrong) order I wouldn't use TLP. Btw. it has very poor performance too, and if you use them, don't nest them (don't use a TLP inside of another one)
Menon Santosh 3-Sep-13 5:24am    
go for rakesh's solution

Hi mk1227,

You just have to add the Buttons to the container control/Form in the right order - this, so called z-order (google?) is the same you see everywhere in Windows. But in your simple case just order them the other way round.

Z-Order isn't to hard to Keep track of in your head with some experience. I have to admit maybe not so easy as it seems to me (I started Windows API programming without any "Designer", just creating the GUI with C++ code-Editor in the old days.)But the concept didn't change.

It's simple: everything added later comes on top (like on your Windows Desktop), every Dock "pushes" the other Dock's away. So I'd recommend not to think to much but "Play" with it. Create a little app with some different colored panels (any other control will do) and set different Dockings and different z-Orders

a useful method to set the z-Order later (not through adding) is to use SetChildIndex method. http://msdn.microsoft.com/en-us/library/system.windows.forms.control.controlcollection.setchildindex.aspx[^]

Kind regards Johannes
 
Share this answer
 
Hello Friend.....You have to use Docking property along with TableLayoutPanel and place All Button into the TableLayoutPanel
use it and enjoy



or you may use belowing code.....


this.Controls.SetChildIndex(textBox1, 2);
this.Controls.SetChildIndex(textBox2, 1);
this.Controls.SetChildIndex(textBox3, 0);
this.textBox1.Dock = System.Windows.Forms.DockStyle.Bottom;
this.textBox2.Dock = System.Windows.Forms.DockStyle.Bottom;
this.textBox3.Dock = System.Windows.Forms.DockStyle.Bottom;
 
Share this answer
 
v2
Comments
Menon Santosh 3-Sep-13 5:25am    
my +5
johannesnestler 3-Sep-13 10:18am    
what? TableLayoutPanel? no 5 for sure...
Menon Santosh 4-Sep-13 1:52am    
i agree SetChildIndex is also other method to achive this output :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900