在C#中的splitpanel或tablelayoutpanel中创建滚动

时间:2018-08-27 19:17:36

标签: c# forms winforms windows-forms-designer

Using tablelayoutPanel

Result of tablelayoutPanel: My labels go out of the screen when i dock them at bot

Using Splitpanel

Result of Split Panel:Messages are overflowed but not creating scroll

  • 第一张图片:使用tablelayoutPanel
  • 第二张图片:tablelayout的结果面板:我的标签不在屏幕上 当我将它们停靠在机器人上
  • 第3张图片:使用Splitpanel
  • 第4张图片:拆分面板的结果:消息溢出但没有 创建滚动

因此,我正在创建一个BOT,它在执行操作时会根据用户的问题做出响应,我正在创建两个标签,一个标签在右侧打印用户的问题,在左侧打印BOT的响应,同时我要滚动面板溢出,但是很不幸,或者可能是缺少我的方法,我无法在底部停靠标签时这样做 这是我标签的代码 (我是C#的新手,请忽略幼稚的内容)

左侧(BOT):

Label label = new Label();
        label.Size = new Size(35, 20);
        label.Font = new Font("Microsoft Sans Serif", 8F);
        label.Text = "IceFrog : I am unable to understand you try expressing in other way";
        label.RightToLeft = RightToLeft.No;
        splitContainer1.Panel1.RightToLeft = RightToLeft.No;
        //label.BorderStyle = BorderStyle.Fixed3D;
        // label.BackColor = Color.LightBlue;
        label.Dock = DockStyle.Bottom;
        splitContainer1.Panel1.Controls.Add(label);

右侧(人):

        Label label = new Label();
        label.Size = new Size(35, 20);
        label.Font = new Font("Microsoft Sans Serif", 8F);
        label.Text = "Human : "+textBox1.Text;
        label.RightToLeft = RightToLeft.No;
        splitContainer1.Panel2.RightToLeft = RightToLeft.No;
        label.TextAlign = ContentAlignment.BottomRight;
        //label.BorderStyle = BorderStyle.Fixed3D;
        // label.BackColor = Color.LightBlue;
        label.Dock = DockStyle.Bottom;
        splitContainer1.Panel2.Controls.Add(label);

1 个答案:

答案 0 :(得分:0)

更改每个面板的AutoScrollMinSize

this.splitContainer1.Panel1.AutoScrollMinSize = new Size(1, 0);
this.splitContainer1.Panel2.AutoScrollMinSize = new Size(1, 0);

或者,您可以使用设计器执行相同的操作

image

要保持新添加的项目可见(在底部),请将这些行添加到您的代码中

 splitContainer1.Panel1.VerticalScroll.Value = splitContainer1.Panel1.VerticalScroll.Maximum;
 splitContainer1.Panel2.VerticalScroll.Value = splitContainer1.Panel2.VerticalScroll.Maximum;