Hi SO-lers,
I'm using the following code to get a TextBox that is not drawing its borders:
public partial class CustomTextBox : TextBox
{
public CustomTextBox()
{
InitializeComponent();
SetStyle(ControlStyles.UserPaint, true);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
int borderWidth = 1;
ControlPaint.DrawBorder(e.Graphics, e.ClipRectangle,
Color.Transparent, borderWidth, ButtonBorderStyle.Solid,
Color.Transparent, borderWidth, ButtonBorderStyle.Solid,
Color.Transparent, borderWidth, ButtonBorderStyle.Solid,
Color.Transparent, borderWidth, ButtonBorderStyle.Solid);
}
}
I seem to miss something inside of OnPaint() because my Font is not the default Font for a textBox anymore (perhaps I have to override another event).
When checking CustomTextBox.Font property it shows me the default "Microsoft SansSerif in 8,25" but when typing text into my textBox the Font definitely looks bigger and bold.
Hope you can help me!
Regards,
inno
[EDIT]
I should mention that if I don't override OnPaint the Font of my CustomTextBox is correct. Only when overriding OnPaint my Font is incorrect (when typing text the font is bigger and seems to be bold). So I think I have to do something to initialize the font correctly inside of OnPaint (but ATM I have no idea how to do this).