带有 FixedSingle 边框的 Winforms TextBox 垂直对齐

Winforms TextBox vertical alignment with FixedSingle border

当您将 TextBox 控件的 BorderStyle 属性 更改为 FixedSingle 时,输入的文本不再正确地在控件内垂直居中。底部的填充比顶部大得多。我怎样才能摆脱这个?

这是在 Windows 7.

是的,有点乱。一种欺骗方法是将边框更改为 none 并在容器的绘制事件中绘制无边框文本框周围的边框:

Rectangle r = new Rectangle(textBox1.Left - 3, textBox1.Top - 3,
                            textBox1.Width + 5, textBox1.Height + 5);
e.Graphics.FillRectangle(SystemBrushes.Window, r);
e.Graphics.DrawRectangle(SystemPens.WindowFrame, r);

结果: