Notifications
Clear all

[Closed] DockStyle.Fill ignoring Location

 e-x

Does setting a control’s DockStyle to Fill ignore its Location?

Image of said problem:

The red panel shouldn’t be behind the green one. I would think it’s Location property should but it below the green panel, unless I’m missing something.

And my code:

mainWin = dotNetObject "MaxCustomControls.MaxForm"
mainWin.size = dotNetObject "System.Drawing.Size" 300 200

p1 = dotNetObject "Panel"
p2.Dock = (dotNetClass "System.Windows.Forms.DockStyle").Top
p1.BackColor = p1.BackColor.fromARGB 0 200 0
p1.size = dotNetObject "System.Drawing.Size" 150 24

p2 = dotNetObject "Panel"
p2.Location =  dotNetObject "System.Drawing.Point" 0 24
p2.Dock = (dotNetClass "System.Windows.Forms.DockStyle").Fill
p2.BackColor = p2.BackColor.fromARGB 200 0 0
p2.BorderStyle = p2.BorderStyle.FixedSingle

mainWin.controls.add p1
mainWin.controls.add p2

mainWin.showmodeless()
4 Replies

fill means set the control’s size and location to fit exactly into it’s parent’s ClientRectangle, so yes it does ‘ignore’ the location property in this case. if you want to align only the left, right and bottom edges you should be able to use dotnet.combineEnums to get the required dockstyle

1 Reply
 e-x
(@e-x)
Joined: 11 months ago

Posts: 0

Not sure you can combine DockStyle enums. Combining Anchor enums works though, and that seems to have fixed my problem. I have to set the Anchor to all sides and make sure the red panel is the same size as my form, minus the size of the green panel. It will then behave exactly as if it’s been fill docked.

Thanks for the help.

first of all you have to fix a bug, and second change the order how you add controls to:


 mainWin.controls.addrange #(p2, p1)
 

that solves a problem.

1 Reply
 e-x
(@e-x)
Joined: 11 months ago

Posts: 0

Well that’s embarrassing…

Thanks for the help, appreciated as always.