|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Dock and Z-Order ProblemsAs I understand it, the control docking order based on the control z-order. So If I have two controls, Control1 & Control2 whose Dock properties are both set to Top, the control that is "Top Most" will appear on the top. I tried changing the z-order in the designer for Control2 by selecting bring to front, but when I show the form, Control1 appear on top. Programatically, I tried settting the z-order by calling the BringToFront method and then changing the Dock as follows: Control1.Dock = DockStyle.None; Control2.Dock = DockStyle.None; Control1.Location = new point (0,0); Control2.Location = new point (0,0); Control2.BringToFront(); Control1.Dock = DockStyle.Top; Control2.Dock = DockStyle.Top; But this still does not work. How do I set Control2 to be on Top of the form? I hope I don't have to muck around with the designer generated code. I am using .Net 2.0. Thanks Opa,
I added a button and two panels to a form (one red and one green for better viewing) and set their Dock properties to "Top" initially. In the Button.Click event handler I was able to change the docking priority with the following logic. private bool _usePanel1 = true; private void button1_Click(object sender, EventArgs e) { //add your logic here for picking which panel you want on top Panel thePanel = _usePanel1 ? panel1 : panel2; thePanel.Dock = DockStyle.None; thePanel.BringToFront(); thePanel.Dock = DockStyle.Top; _usePanel1 = !_usePanel1; } I think the main thing is to keep the other control docked to the top while you bring the desired control to the front and then dock it to the top. Regards, Geoff http://nonspect.com Opa wrote: Show quote > I have a lingering problem with control docking and z-order. > As I understand it, the control docking order based on the control z-order. > So If I have two controls, Control1 & Control2 whose Dock properties are both > set to Top, the control that is "Top Most" will appear on the top. I tried > changing > the z-order in the designer for Control2 by selecting bring to front, but > when I show > the form, Control1 appear on top. > > Programatically, I tried settting the z-order by calling the BringToFront > method > and then changing the Dock as follows: > > Control1.Dock = DockStyle.None; > Control2.Dock = DockStyle.None; > > Control1.Location = new point (0,0); > Control2.Location = new point (0,0); > > Control2.BringToFront(); > > Control1.Dock = DockStyle.Top; > Control2.Dock = DockStyle.Top; > > > But this still does not work. How do I set Control2 to be on Top of the form? > I hope I don't have to muck around with the designer generated code. > I am using .Net 2.0. > > Thanks Geoff, Thanks for the reply.
I tried your suggestion, but I still have the same problem. I think it depends on the designer generated code. In which case, I don't want to modify this section. Any other ideas? Show quote "Geoff Munday" wrote: > Opa, > > I added a button and two panels to a form (one red and one green for > better viewing) and set their Dock properties to "Top" initially. In > the Button.Click event handler I was able to change the docking > priority with the following logic. > > private bool _usePanel1 = true; > > private void button1_Click(object sender, EventArgs e) > { > //add your logic here for picking which panel you want on > top > > Panel thePanel = _usePanel1 ? panel1 : panel2; > > thePanel.Dock = DockStyle.None; > thePanel.BringToFront(); > thePanel.Dock = DockStyle.Top; > > _usePanel1 = !_usePanel1; > } > > I think the main thing is to keep the other control docked to the top > while you bring the desired control to the front and then dock it to > the top. > > Regards, > > Geoff > http://nonspect.com > > > Opa wrote: > > I have a lingering problem with control docking and z-order. > > As I understand it, the control docking order based on the control z-order. > > So If I have two controls, Control1 & Control2 whose Dock properties are both > > set to Top, the control that is "Top Most" will appear on the top. I tried > > changing > > the z-order in the designer for Control2 by selecting bring to front, but > > when I show > > the form, Control1 appear on top. > > > > Programatically, I tried settting the z-order by calling the BringToFront > > method > > and then changing the Dock as follows: > > > > Control1.Dock = DockStyle.None; > > Control2.Dock = DockStyle.None; > > > > Control1.Location = new point (0,0); > > Control2.Location = new point (0,0); > > > > Control2.BringToFront(); > > > > Control1.Dock = DockStyle.Top; > > Control2.Dock = DockStyle.Top; > > > > > > But this still does not work. How do I set Control2 to be on Top of the form? > > I hope I don't have to muck around with the designer generated code. > > I am using .Net 2.0. > > > > Thanks > > Opa,
I tested that code both in the designer and at runtime and it worked like a charm. What type of controls are you docking? Make sure you aren't setting both controls' Location properties to Point(0, 0). Give each a unique Y point and the dock them both to the top. Then...leave the control you ultimately want on the bottom still docked to the "Top" and adjust the one you want above the other one using the same code as below. thePanel.Dock = DockStyle.None; thePanel.BringToFront(); thePanel.Dock = DockStyle.Top; Only adjust the control you want on top and don't give it a new Location during that process. Let the docking handle that. Feel free to post some code if you still can't get it to work. Regards, Geoff http://nonspect.com Opa wrote: Show quote > Geoff, Thanks for the reply. > > I tried your suggestion, but I still have the same problem. I think > it depends on the designer generated code. In which case, I don't > want to modify this section. > > Any other ideas? > > "Geoff Munday" wrote: > > > Opa, > > > > I added a button and two panels to a form (one red and one green for > > better viewing) and set their Dock properties to "Top" initially. In > > the Button.Click event handler I was able to change the docking > > priority with the following logic. > > > > private bool _usePanel1 = true; > > > > private void button1_Click(object sender, EventArgs e) > > { > > //add your logic here for picking which panel you want on > > top > > > > Panel thePanel = _usePanel1 ? panel1 : panel2; > > > > thePanel.Dock = DockStyle.None; > > thePanel.BringToFront(); > > thePanel.Dock = DockStyle.Top; > > > > _usePanel1 = !_usePanel1; > > } > > > > I think the main thing is to keep the other control docked to the top > > while you bring the desired control to the front and then dock it to > > the top. > > > > Regards, > > > > Geoff > > http://nonspect.com > > > > > > Opa wrote: > > > I have a lingering problem with control docking and z-order. > > > As I understand it, the control docking order based on the control z-order. > > > So If I have two controls, Control1 & Control2 whose Dock properties are both > > > set to Top, the control that is "Top Most" will appear on the top. I tried > > > changing > > > the z-order in the designer for Control2 by selecting bring to front, but > > > when I show > > > the form, Control1 appear on top. > > > > > > Programatically, I tried settting the z-order by calling the BringToFront > > > method > > > and then changing the Dock as follows: > > > > > > Control1.Dock = DockStyle.None; > > > Control2.Dock = DockStyle.None; > > > > > > Control1.Location = new point (0,0); > > > Control2.Location = new point (0,0); > > > > > > Control2.BringToFront(); > > > > > > Control1.Dock = DockStyle.Top; > > > Control2.Dock = DockStyle.Top; > > > > > > > > > But this still does not work. How do I set Control2 to be on Top of the form? > > > I hope I don't have to muck around with the designer generated code. > > > I am using .Net 2.0. > > > > > > Thanks > > > > Opa,
Docking order depends on the order of the controls in the parent's Controls collection. This could be considered as design-time z-roder and I don't think it has anything to do with run-time z order of the controls from Windows perspective. If you want to change the docking order at run-time you need to rearange the Controls collection of the parent control. -- Show quoteHTH Stoitcho Goutsev (100) "Opa" <O**@discussions.microsoft.com> wrote in message news:F0ECDAD6-5A64-40AD-BF77-8285409131EF@microsoft.com... > Geoff, Thanks for the reply. > > I tried your suggestion, but I still have the same problem. I think > it depends on the designer generated code. In which case, I don't > want to modify this section. > > Any other ideas? > > "Geoff Munday" wrote: > >> Opa, >> >> I added a button and two panels to a form (one red and one green for >> better viewing) and set their Dock properties to "Top" initially. In >> the Button.Click event handler I was able to change the docking >> priority with the following logic. >> >> private bool _usePanel1 = true; >> >> private void button1_Click(object sender, EventArgs e) >> { >> //add your logic here for picking which panel you want on >> top >> >> Panel thePanel = _usePanel1 ? panel1 : panel2; >> >> thePanel.Dock = DockStyle.None; >> thePanel.BringToFront(); >> thePanel.Dock = DockStyle.Top; >> >> _usePanel1 = !_usePanel1; >> } >> >> I think the main thing is to keep the other control docked to the top >> while you bring the desired control to the front and then dock it to >> the top. >> >> Regards, >> >> Geoff >> http://nonspect.com >> >> >> Opa wrote: >> > I have a lingering problem with control docking and z-order. >> > As I understand it, the control docking order based on the control >> > z-order. >> > So If I have two controls, Control1 & Control2 whose Dock properties >> > are both >> > set to Top, the control that is "Top Most" will appear on the top. I >> > tried >> > changing >> > the z-order in the designer for Control2 by selecting bring to front, >> > but >> > when I show >> > the form, Control1 appear on top. >> > >> > Programatically, I tried settting the z-order by calling the >> > BringToFront >> > method >> > and then changing the Dock as follows: >> > >> > Control1.Dock = DockStyle.None; >> > Control2.Dock = DockStyle.None; >> > >> > Control1.Location = new point (0,0); >> > Control2.Location = new point (0,0); >> > >> > Control2.BringToFront(); >> > >> > Control1.Dock = DockStyle.Top; >> > Control2.Dock = DockStyle.Top; >> > >> > >> > But this still does not work. How do I set Control2 to be on Top of >> > the form? >> > I hope I don't have to muck around with the designer generated code. >> > I am using .Net 2.0. >> > >> > Thanks >> >> Hello Opa,
Whichever control is "backmost" will be higher on the form. So in the designer select the control you want to be at the very top and click the Send To Back button. -Boo Show quote > I have a lingering problem with control docking and z-order. > As I understand it, the control docking order based on the control > z-order. > So If I have two controls, Control1 & Control2 whose Dock properties > are both > set to Top, the control that is "Top Most" will appear on the top. I > tried > changing > the z-order in the designer for Control2 by selecting bring to front, > but > when I show > the form, Control1 appear on top. > Programatically, I tried settting the z-order by calling the > BringToFront > method > and then changing the Dock as follows: > Control1.Dock = DockStyle.None; > Control2.Dock = DockStyle.None; > Control1.Location = new point (0,0); > Control2.Location = new point (0,0); > Control2.BringToFront(); > > Control1.Dock = DockStyle.Top; > Control2.Dock = DockStyle.Top; > But this still does not work. How do I set Control2 to be on Top of > the form? > I hope I don't have to muck around with the designer generated code. > I am using .Net 2.0. > Thanks > |
|||||||||||||||||||||||