VB had a "line" control, just a simple line that let you separate
controls without the wasted space of a Groupbox. Did CSharp drop
this?
Dom
Here is a better example if you want to show a 3DLine effect.
public class Foo : UserControl
{
int mSpacing = 0;
Border3DStyle mBorderStyle =
(Border3DStyle)Border3DStyle.Etched;
private System.ComponentModel.IContainer components = null;
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.SuspendLayout();
//
// Line
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F,
13F);
this.AutoScaleMode =
System.Windows.Forms.AutoScaleMode.Font;
this.Name = "Line";
this.Size = new System.Drawing.Size(150, 16);
this.ResumeLayout(false);
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should
be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#endregion
public Foo()
{
InitializeComponent();
SetStyle(ControlStyles.DoubleBuffer, true);
SetStyle(ControlStyles.SupportsTransparentBackColor,
true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.ResizeRedraw, true);
Name = "3DLine";
this.Size = new System.Drawing.Size(150, 16);
UpdateStyles();
}
public override string Text
{
get{ return base.Text;}
set { base.Text = value; }
}
public string HeaderText
{
get { return Text; }
set { Text = value; Invalidate(); }
}
public Border3DStyle LineStyle
{
get { return mBorderStyle; }
set
{
if (value != mBorderStyle) { mBorderStyle = value;
Invalidate(); }
}
}
public int Spacing
{
get { return mSpacing; }
set
{
if (value != mSpacing) { mSpacing = value;
Invalidate(); }
}
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
using (Brush b = new SolidBrush(ForeColor))
{
StringFormat sf = StringFormat.GenericTypographic;
SizeF s = e.Graphics.MeasureString(Text, Font, Width);
e.Graphics.DrawString(Text, Font, b, 0, (Height / 2) -
(s.Height / 2), sf);
if (s.Width + Spacing < Width)
{
Point p = new Point(Convert.ToInt32(s.Width +
Spacing), Convert.ToInt32(s.Height / 2));
ControlPaint.DrawBorder3D(e.Graphics, p.X,
(Height / 2), (Width - p.X), 5, mBorderStyle, Border3DSide.Top);
}
}
}
}