'How to make a vertical separator in a Windows Forms Application (C#)
Solution 1:[1]
This is too late to answer this, but for the ease of anyone who ends up here searching:
As Line control deprecated, just use a Label control with AutoSize = false and Size = 1,xx with any BackColor you like your line to be.
Replace
xxin the Size with actual height.
Solution 2:[2]
public class VertSep : Control
{
private Color lineColor;
private Pen linePen;
public VertSep()
{
this.LineColor = Color.LightGray;
SetStyle( ControlStyles.SupportsTransparentBackColor, true );
}
public Color LineColor
{
get
{
return this.lineColor;
}
set
{
this.lineColor = value;
this.linePen = new Pen( this.lineColor, 1 );
this.linePen.Alignment = PenAlignment.Inset;
Refresh();
}
}
protected override void Dispose( bool disposing )
{
if( disposing && this.linePen != null )
{
this.linePen.Dispose();
this.linePen = null;
}
base.Dispose( disposing );
}
protected override void OnPaint( PaintEventArgs e )
{
var g = e.Graphics;
int x = this.Width / 2;
g.DrawLine( linePen, x, 0, x, this.Height );
base.OnPaint( e );
}
}
Solution 3:[3]
You'll have to move all your contents inside a SplitContainer. This container contains two panels and a divider. You'll have to place the controls on one side and the image on the other panel.
In your particular case you'll probably have to start over.
Using the designer you should set the SplitContainer's Dock property on Fill. You can move the divider by selecting it and dragging (this is only possible if you have the SplitContainer selected). Once the divider is in the right place, it might be wise to set the FixedPanel property to the left panel as you probably don't want this panel to grow when maximizing.
It's still possible to move the divider in the application as long as the property IsSplitterFixed is set to False.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Shahaboddin |
| Solution 2 | antiduh |
| Solution 3 | Oceans |

