Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows.Forms SplitContainer.SplitterWidth will not stay set at runtime

Tags:

c#

.net

winforms

I am trying to put a cool little image like this

one of these guys

For my split container drag button.

I do the following in the OnPaint Event

private void splitContainer1_Paint(object sender, PaintEventArgs e)
    {
        var control = sender as SplitContainer;            

        e.Graphics.DrawImage("...".Properties.Resources.divider, control.SplitterRectangle, 0, 0, 1040, 50, GraphicsUnit.Pixel);

    } 

It does draw the image as I would like, the problem is that the height is ALWAYS 4 pixels. In the designer I set the SplitterWidth to 15, but at runtime it always stays at 4. So, only 4 pixels actually shows up.

like image 437
Jonathan Henson Avatar asked Jan 11 '12 05:01

Jonathan Henson


1 Answers

Yes, according to your comment, having the SplitterPanel inside a TableLayoutPanel does make the runtime forget the SplitterWidth setting, so I did duplicate the problem. TableLayoutPanels are weird creatures.

The unfortunately obvious work-around:

public Form1() {
  InitializeComponent();
  splitContainer1.SplitterWidth = 15;
}
like image 90
LarsTech Avatar answered Nov 06 '22 11:11

LarsTech