0
我設計了一個Form用作打印模板。它旨在填寫表單,因此在繪製頁面前我必須考慮頁面邊距。在運行時更改Windows Form Panel位置
我目前的問題是試圖讓System.Windows.Forms.Panel控件轉移由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);
}
}
}
}
我的小控制檯輸出被擊中,每Panel,我從我的模板表單傳遞。
獲取或設置控制相對於其容器的左上角的的左上角的座標。
那麼,爲什麼移位Panel使用Margins不動Location?
我需要做些什麼來糾正?