I have designed a Form to use as a Template for printing. It is designed to fill the form, so I have to take into account the Page Margins before drawing them.
My current issue is trying to get the System.Windows.Forms.Panel controls to shift over by the amount specified by the System.Drawing.Printing.Margins.
private static void MarginShift(Control ctrl, Margins m) {
Label lbl = ctrl as Label;
if (lbl != null) {
lbl.Location = new Point(lbl.Location.X + m.Left, lbl.Location.Y + m.Top);
} else {
Panel pnl = ctrl as Panel;
if (pnl != null) {
int x = pnl.Location.X;
int y = pnl.Location.Y;
pnl.Location = new Point(x + m.Left, y + m.Top);
if ((pnl.Location.X == x) && (pnl.Location.Y == y) &&
((0 < m.Left) || (0 < m.Top))) {
Console.WriteLine("WTF?");
}
foreach (Control c2 in pnl.Controls) {
MarginShift(c2, m);
}
}
}
}
My little Console output gets hit for every Panel that I pass from my Template Form.
Microsoft’s documentation of the Panel control says this of the Location value:
Gets or sets the coordinates of the upper-left corner of the control relative to the upper-left corner of its container.
So, why does shifting a Panel using the Margins not move the Location?
What do I need to do to correct this?
Never mind. Panels were docked to the form.