CoderBrien
CoderBrien

Reputation: 693

C#/winforms Panel with vertical scrollbar on left?

How do I get the (autoscroll) vertical scrollbar to be on the left in a System.Windows.Forms.Panel?

Note: I tried modifying the window style ala the textbox question and it did not work.

I tried by subclassing Panel and pinvoking in the ctor, setting CreateParams.Style in the ctor, and by overriding CreateParams getter to tweak the style. no go.

Upvotes: 3

Views: 1524

Answers (1)

Reza Aghaei
Reza Aghaei

Reputation: 125197

If you add WS_EX_LEFTSCROLLBAR extended style to the control it shows scrollbar on left side:

using System.Windows.Forms;
public class ExPanel : Panel
{
    private const int WS_EX_LEFTSCROLLBAR = 0x00004000;
    protected override CreateParams CreateParams
    {
        get
        {
            var cp = base.CreateParams;
            cp.ExStyle = cp.ExStyle | WS_EX_LEFTSCROLLBAR;
            return cp;
        }
    }
}

Also keep in mind, Setting RightToLeft property to Yes will do the trick for you, but since the RightToLeft property is an ambient property, then all children of the panel will also inherit that value and will be right to left. What I have shared here in this answer is just showing scrollbar at left side without affecting RightToLeft.

Upvotes: 6

Related Questions