如何绘制一个与System.Windows.Forms.TextBox相同的框架

时间:2016-06-16 16:45:13

标签: c# winforms textbox frame visual-styles

在WinForms中,如何绘制与System.Windows.Forms.TextBox控件中相同的帧?

我尝试将VisualStyleRendererVisualStyleElement.TextBox.TextEdit.Normal参数一起使用,但它会绘制一条奇怪的灰线。

VisualStyleElement.Button.PushButton.Normal按钮正常工作。 它像按钮一样绘制面部,但对于TextBox,它绘制一个灰色线条边框。

我使用了以下代码:

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));
}

查看屏幕截图。

左侧是编辑和按钮控件。

右边是VisualStyleRenderer.DrawBackground

绘制的内容

enter image description here

0 个答案:

没有答案