Home » c# » c# – Is there a way to toggle/fix a menu while scrolling?-Exceptionshub

c# – Is there a way to toggle/fix a menu while scrolling?-Exceptionshub

Posted by: admin February 24, 2020 Leave a comment

Questions:

I want to build a Windows Forms App that has a menu (several labels) on it’s left side which is toggled. On the right side there should be some columns i can scroll through. Jst like Excel with it’s fixed rownumbers.

Is there a way to do this? Preferably an easy one.Something like this.

How to&Answers:

I think you can use two panels to make the form like the picture you provided.

The following code is a code example and you can refer to it.

 public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        ScrollBar hScrollBar1 = new HScrollBar();
        private void Form1_Load(object sender, EventArgs e)
        {
            panel1.BorderStyle = BorderStyle.FixedSingle;
            panel1.Dock = DockStyle.Left;
            panel2.BorderStyle = BorderStyle.FixedSingle;
            panel2.Dock = DockStyle.Fill;
            hScrollBar1.Dock = DockStyle.Bottom;
            hScrollBar1.Scroll += new ScrollEventHandler(hScroller_Scroll);
            panel2.Controls.Add(hScrollBar1);
            panel2.HorizontalScroll.Visible = false;
            panel2.HorizontalScroll.Enabled = true;
        }
        private void hScroller_Scroll(object sender, ScrollEventArgs e)
        {
            panel2.HorizontalScroll.Value = e.NewValue;
        }
    }

The specific result:
enter image description here