简体   繁体   中英

Creating Scroll in splitpanel or tablelayoutpanel in C#

使用tablelayoutPanel

tablelayoutPanel的结果:当我将它们停靠在bot上时,我的标签不显示在屏幕上

使用Splitpanel

拆分面板的结果:消息溢出但未创建滚动

  • 1st image :Using tablelayoutPanel
  • 2nd image :Result of tablelayoutPanel: My labels go out of the screen when i dock them at bot
  • 3rd image :Using Splitpanel
  • 4th image :Result of Split Panel:Messages are overflowed but not creating scroll

So i am creating a BOT that responds according the user's question while doing it,i am creating two labels one which print user's question on the right and print respond of BOT at left side, while doing it i want scroll as the panel go overflow but unfortunately or maybe lack of my approach i cant do it while docking label at the bottom here is the code of my labels (i am new to c# kindly ignore childish stuff)

LEFT SIDE (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);

RIGHT SIDE (human):

        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);

Change the AutoScrollMinSize for each pannel

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

Alternatively, you can do the same using the designer

图片

To keep newly added items visible (at the bottom) add those lines to your codes

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM