使用自定义颜色替换/重绘TextBox 3D边框
情景
在WinForms中 ,当BorderStyle
属性设置为Flat
, None
或Fixed3D
时,我已经将文本 Fixed3D
分类为使用纯色绘制我自己的边框。
问题
当我的TextBox属性设置为Fixed3D
,当我尝试使用颜色绘制边框时,表面上的边框未正确绘制:
您在图像中看到的是一个缩放的TextBox,其中包含:
BackColor =黑色
BorderStyle = Fixed3D(白色的东西)
红色的是我的边界意图。
题
在C#或VB.Net中,我如何替换/重绘3D边框来做我想要的?,我的意思是替换/隐藏/重绘上面图像的白色边框。
码
这是我在OnPaint
方法上尝试过的:
Using g As Graphics = Graphics.FromHwnd(Me.Handle) ' Dim rect As Rectangle = New Rectangle(0, 0, Me.Width, Me.Height) ' Dim pen As New Pen(Color.Black, 2) ' pen.Alignment = PenAlignment.Inset ' g.DrawRectangle(pen, rect) ControlPaint.DrawBorder(Graphics.FromHwnd(Me.Handle), Me.ClientRectangle, Me.borderColor1, ButtonBorderStyle.Solid) End Using
我也尝试使用DrawBorder3D
方法,但它的任何重载都接受一种颜色?