在SplitContainer中居中标签不起作用

时间:2015-06-13 19:15:24

标签: c# location alignment label

我正在尝试使用以下代码将标签置于SplitContainer中:

label1.Location = new Point((label1.Parent.ClientSize.Width / 2) - (label1.Width / 2),
                          (label1.Parent.ClientSize.Height / 2) - (label1.Height / 2));

这看起来好像是在起作用。我使用标签来保存文档的标题。 但是在我再次加载SAME文档之后,再次将SAME文本放入标签内并再次调用SAME方法,使标签居中,标签放下约5个像素。 有谁知道为什么会发生这种情况?

€:我刚才看到SplitContainers(它是父级)高度在Form1_Load之后从20变为25

Edit2:

private void splitContainer1_Panel1_SizeChanged(object sender, EventArgs e)
    {
        label1.Location = new Point((label1.Parent.ClientSize.Width / 2) - (label1.Width / 2),
                          (label1.Parent.ClientSize.Height / 2) - (label1.Height / 2)); 
    }

0 个答案:

没有答案