The custom textbox displays the text as expected when not on edit mode, how to show the text vertically centered, with same font and not overlapped in edit mode?
The textbox must allow set the height without affecting the font size or vice versa
My code for the custom textbox:
public partial class TextboxCommon : TextBox
{
public TextboxCommon() : base()
{
SetStyle(ControlStyles.UserPaint, true);
AutoSize = false;
BorderStyle = BorderStyle.None;
TextAlign = HorizontalAlignment.Left;
Font = new Font("Calibri light", 16, GraphicsUnit.Point);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Pen penBorder = new Pen(Color.Red, 1);
Rectangle rectBorder = new Rectangle(e.ClipRectangle.X, e.ClipRectangle.Y, e.ClipRectangle.Width - 1, e.ClipRectangle.Height - 1);
e.Graphics.DrawRectangle(penBorder, rectBorder);
Brush brush = new SolidBrush(Color.Purple);
StringFormat stringFormat = new StringFormat
{
LineAlignment = StringAlignment.Center,
Alignment = StringAlignment.Near
};
e.Graphics.DrawString(Text, this.Font, brush, rectBorder, stringFormat);
}
}