Replace/Redraw a TextBox 3D border using a custom color

不羁岁月 提交于 2019-12-10 11:55:51

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!