In WinForms how do I draw a frame the same as in a System.Windows.Forms.TextBox
control?
I tried to use VisualStyleRenderer
with the VisualStyleElement.TextBox.TextEdit.Normal
parameter but it draws a strange gray line.
VisualStyleElement.Button.PushButton.Normal
for a button works correctly.
It draws the face just as the button but for TextBox
it draws a gray line border.
I used the following code:
private void panel1_Paint (object sender, PaintEventArgs e)
{
VisualStyleRenderer vsr = new VisualStyleRenderer(VisualStyleElement.TextBox.TextEdit.Normal);
vsr.DrawBackground (e.Graphics, new Rectangle (500, 12, 100, 20));
vsr = new VisualStyleRenderer (VisualStyleElement.Button.PushButton.Normal);
vsr.DrawBackground (e.Graphics, new Rectangle (500, 47, 100, 23));
}
Look at the screenshot.
On the left are Edit and Button controls.
On the right is what gets drawn by VisualStyleRenderer.DrawBackground