0

我尝试使用 SpliterContainer 和带有按钮的控制面板创建具有 2 列的简单应用程序。我希望它在每个屏幕上看起来都不错。这就是为什么我决定使用元素的相对位置。

我阅读了文档和不同的论坛,但我得到了一些奇怪的东西。拆分器的第二列根本没有出现。

结果

拜托,你能帮我找出这个问题的原因吗?

private void Form1_Load(object sender, EventArgs e)
        {
            WindowState = FormWindowState.Maximized;

            int screenWidth = Screen.PrimaryScreen.Bounds.Width;
            int screenHeight = Screen.PrimaryScreen.Bounds.Height;

            //set form size
            this.Size = new Size(screenWidth, screenHeight);

            //set button panel size
            const double percentOfHeightPanel = 0.05;
            int heightOfPanelButton = Convert.ToInt32(screenHeight * percentOfHeightPanel);
            this.panel_button.Size = new System.Drawing.Size(screenWidth, heightOfPanelButton);
            this.panel_button.Location = new Point(0, 0);


            //set splitContainer size
            int widthOfContainer = Convert.ToInt32(0.5 * screenWidth);
            int heightOfContainers = Convert.ToInt32(screenHeight * (0.95));
            splitContainer1.Panel1.MinimumSize = new Size(widthOfContainer, heightOfContainers);
            splitContainer1.Panel2.MinimumSize = new Size(widthOfContainer, heightOfContainers);
            splitContainer1.Location = new Point(0, heightOfPanelButton);
            //this.splitContainer1.Panel2MinSize = screenWidth - widthOfContainer;

            //set textBox size                
            this.textBox1.Multiline = true;
            this.textBox1.Location = new Point(0, heightOfPanelButton);
            this.textBox1.MinimumSize = new System.Drawing.Size(widthOfContainer, heightOfContainers);

            this.textBox2.Multiline = true;
            this.textBox2.Location = new Point(widthOfContainer, heightOfPanelButton);
            this.textBox1.MinimumSize = new System.Drawing.Size(widthOfContainer, heightOfContainers);
        }
4

1 回答 1

1

如果你想要两个有两个相同大小的分隔板集

splitContainer1.SplitterDistance = 
                          (splitContainer1.Width - splitContainer1.SplitterWidth) / 2;

然后设置

splitContainer1.IsSplitterFixed = true;

您可以在设计时手动设置这两个属性。然后,用户将无法调整面板的大小,并且面板将自动调整为相同大小。

考虑使用 aTableLayoutPanel代替。

如果进一步,两侧应该看起来相同,请将您的控件放在 a 上UserControl并将它们的两个实例放入两个面板中,并将停靠属性设置为Fill

于 2013-09-08T14:23:00.690 回答