4

在 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

在此处输入图像描述

4

0 回答 0