I have tried the following, which draws the border but clears the Text
when the control does not have focus.
Please help.
----------------------------------------------------------
1. Set the ControlStyle to "UserPaint" in the constructor:
public MyTextBox()
{
// This call is required by the Windows.Forms Form Designer.
this.SetStyle(ControlStyles.UserPaint,true);
InitializeComponent();
// TODO: Add any initialization after the InitForm call
}
2. Add the following code to the overrided OnPaint method.
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
int borderWidth = 1;
Color borderColor = Color.Blue;
ControlPaint.DrawBorder(e.Graphics, e.ClipRectangle, borderColor,
borderWidth, ButtonBorderStyle.Solid, borderColor, borderWidth,
ButtonBorderStyle.Solid, borderColor, borderWidth,
ButtonBorderStyle.Solid,
borderColor, borderWidth, ButtonBorderStyle.Solid);
}