C# Anchor property doesn't seem to work

flamey picture flamey · Oct 21, 2009 · Viewed 28.8k times · Source

I added some controls to my form and changed Anchor property how I'd expect this to work, but when I resize the form at the runtime, the controls stay at the same place.

For example, I have two buttons in bottom right corner of a form - they are on the form, no containers or anything like that. Anchor = Bottom, Right. FormBorderStyle = Sizable. But when I drag-resize the form while running, buttons do not move.

Am I missing something?

c# 2005

Answer

Oliver picture Oliver · Oct 21, 2009

Another possibility would be that you accidentally placed your buttons not directly on the form. Instead you put them in some container (eg. panel, tableLayoutPanel, etc) and this container doesn't have set its anchoring or docking values correct.

Just to be absolutely sure you should take a look into designer.cs and check if your buttons are added directly to the form by this.Controls.Add() function or if they are added in any other Controls-List (eg. panel.Controls.Add()).