问题
SCENARIO
In WinForms, I've sub-classed a Textbox to draw my own border with a solid color when BorderStyle
property is set to Flat
, None
, or Fixed3D
.
PROBLEM
When I try to draw a border with a color when my TextBox property is set Fixed3D
, the border is not properly drawn on the surface:

What you see in the image is a zoomed TextBox with:
BackColor = Black
BorderStyle = Fixed3D (the white thing)
And the red thing is my intent of border.
QUESTION
In C# or VB.Net, how I can replace/redraw the 3D border to do what I want?, I mean replace/hide/redraw the white border of the image above.
CODE
This is what I've tried on the OnPaint
method:
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
Also I've tried to use the DrawBorder3D
method but any of its overloads accept a color?
来源:https://stackoverflow.com/questions/27235587/replace-redraw-a-textbox-3d-border-using-a-custom-color