One of my windows constitutes many controls, I need to set anchor property top and right ,Note: I need to handle positional property independently for each control. I don't want to set this property manually .Need help to set anchor property for the control dynamically.
I write the bellow syntax
DynamicControlsProperty od = new DynamicControlsProperty(); foreach (Control item in this.controls) { item.Anchor = AnchorStyles.None; item.Anchor = (AnchorStyles.Top | AnchorStyles.Right); }
Using the above syntax on my window form, controls are not appear as anchor set on the above syntax.Controls are appear as default anchor set.
Remarks. Use the Anchor property to define how a control is automatically resized as its parent control is resized. Anchoring a control to its parent control ensures that the anchored edges remain in the same position relative to the edges of the parent control when the parent control is resized.
The docking mode can be any side of the control's container, or set to fill the remaining space of the container.
Anchor refers to the position a control has relative to the edges of the form. A textbox, for example, that is anchored to the left edge of a form will stay in the same position as the form is resized. Docking refers to how much space you want the control to take up on the form.
DockPanel defines an area to arrange child elements relative to each other, either horizontally or vertically. With DockPanel you can easily dock child elements to top, bottom, right, left and center using the Dock property.
Try to use this
foreach (Control item in this.Controls) { item.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With