简体   繁体   中英

Add vertical Scrollbar and change its color not working

I create a Form in Visual Studio that contains many fields to display; the fields need extra area (larger than screen size).
I am trying to resize the Form but it prevents me from doing it.
I tried to add a vertical Scrollbar but also didn't work.

Note that I want to add a new Scrollbar to my Form and change its color, not activate the default Scrollbars.

private void Form1_Load(object sender, EventArgs e)
{
    VScrollBar vScroller = new VScrollBar();
    vScroller.Dock = DockStyle.Right;
    vScroller.Width = 30;
    vScroller.Height = 200;
    vScroller.Name = "VScrollBar1";
    this.Controls.Add(vScroller);
 }

You can use the following code to add a vertical Scrollbar successfully.

 ScrollBar vScrollBar1 = new VScrollBar();
    private void Form1_Load(object sender, EventArgs e)
    {
        vScrollBar1.Dock = DockStyle.Right;
        vScrollBar1.Dock = DockStyle.Right;
        vScrollBar1.Scroll += new ScrollEventHandler(vScroller_Scroll);
        panel1.Controls.Add(vScrollBar1);
        panel1.VerticalScroll.Visible = false;
        panel1.VerticalScroll.Enabled = true;
        this.Controls.Add(vScrollBar1);

    }
    private void vScroller_Scroll(object sender, ScrollEventArgs e)
    {
        panel1.VerticalScroll.Value = e.NewValue;
    }

As for failure for changing the color, you can look at the Vertical Scrollbar color does not change . It describes the reason clearly.

Result: 在此处输入图片说明

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