private BorderStyle m_bdsBorder = BorderStyle.Fixed3D;
//This code was created to match the implementation by the Label class
[Category("Appearance"),
DefaultValue(BorderStyle.Fixed3D),
Description("Determines if the label has a visible border.")]
public BorderStyle BorderStyle {
get {
return m_bdsBorder;
}
set {
if (Enum.IsDefined(typeof(BorderStyle), value)) {
m_bdsBorder = value;
this.Invalidate();
} else {
throw new InvalidEnumArgumentException(
"value", (int) value, typeof(BorderStyle));
}
}
}
protected override void WndProc(ref Message msg) {
if (this.BorderStyle == BorderStyle.Fixed3D) {
//The border does not need to be clipped so just pass on the method call
base.WndProc(ref msg);
} else if (msg.Msg == 15) {
//This code is executed before the control painting is performed
//The painting region must be clipped to get rid of the border before
Rectangle rctBound = this.Bounds;
if (this.BorderStyle == BorderStyle.FixedSingle) {
//Take off one pixel the whole way around the border
rctBound.Offset(1 - rctBound.X, 1 - rctBound.Y);
rctBound.Size -= new Size(2, 2);
} else {
//Take off two pixels the whole way around the border
rctBound.Offset(2 - rctBound.X, 2 - rctBound.Y);
rctBound.Size -= new Size(3, 3);
}
//The ComboBox painting area is clipped to get rid of the 3D border
this.Region = new Region(rctBound);
base.WndProc(ref msg);
if (this.BorderStyle == BorderStyle.FixedSingle) {
//Draw the single line border after the call to the painting methods
//An additional pixel must be trimmed off of the border size to accomodate
//the way that the painting methods perform
rctBound.Size -= new Size(1, 1);
this.CreateGraphics().DrawRectangle(new Pen(Color.Black), rctBound);
}
} else {
//Pass on all other messages
base.WndProc(ref msg);
}
}