The most obvious way to right-align a Label
in WinForms doesn\'t work: setting anchor to Top/Bottom Right and TextAlign to TopRight. If the text changes the lab
int rowIndex=1;
var lbx = new Label();
lbx.AutoSize = true; // default is false.
lbx.BackColor = Color.Green; // to see if it's aligning or not
lbx.Text = "Iam Autosize=true";
lbx.Anchor = AnchorStyles.Right;
tlPanel.Controls.Add(lbx, 0, rowIndex);
var dtp = new DateTimePicker();
dtp.Anchor = AnchorStyles.Left;
tlPanel.Controls.Add(dtp, 1, rowIndex);
//--- row 2 autosize false
rowIndex=2;
var lbx2 = new Label();
lbx2.AutoSize = false; // default is false.
lbx2.BackColor = Color.Green; // to see if it's aligning or not
lbx2.Text = "AutoSz=false";
lbx2.Anchor = AnchorStyles.Right;
tlPanel.Controls.Add(lbx2, 0, rowIndex);
var dtp = new DateTimePicker();
dtp.Anchor = AnchorStyles.Left;
tlPanel.Controls.Add(dtp, 1, rowIndex);