2012-08-02 52 views
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控制微软的文档说的Location值这样的:

获取或设置控制相对于其容器的左上角的的左上角的坐标。

那么,为什么移位Panel使用Margins不动Location

我需要做些什么来纠正?

回答

1

没关系。面板被停靠在表格上。