我正在尝试为我的文本框创建一个自定义 onPaint,它正在工作......它正在工作但是当我尝试输入内容时,一个文本框正在呈现在 textbox 上方。
这是我的构造函数:
public TextBox()
{
Font = new Font("Segoe UI", 11F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0)));
BackColor = Color.White;
BorderColor = Color.Gray;
BorderStyle = BorderStyle.None;
SetStyle(ControlStyles.UserPaint, true);
}
还有onPaint:
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
g.FillRectangle(backgroundBrush, 0, 0, this.Width, this.Height);
SizeF fontSize = g.MeasureString(Text, Font);
g.DrawString(Text, Font, new SolidBrush(ForeColor), new PointF(5, 5), cFormat);
g.DrawRectangle(borderPen, borderPen.Width / 2, borderPen.Width / 2,
this.Width - borderPen.Width, this.Height - borderPen.Width);
}