Search code examples
c#winformsdocking

Dock FIll Anchor Right


In a winform program where I have a reportviewer control a simply want the control to adjust its height with respect to Form's height changes, without changing its witdh as well as it horizontal location. I define:

reportViewer1.Anchor = AnchorStyles.Right;
reportViewer1.Dock = DockStyle.Fill;
reportViewer1.MaximumSize.Width.Equals(860);
reportViewer1.MaximumSize.Height.Equals(1600);

However the reportviewer gets to the left corner of the Form (Anchor doesn't seem to take effect) What am I missing?


Solution

  • If you want a control to preserve its width and to adjust its height when the Form resized, set Anchor to AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left and Dock to DockStyle.None.