Drawing Rectangle around Custom TextBox control

寵の児 提交于 2020-01-25 12:32:20

问题


I'm trying to create a custom TextBox control that will have two additional properties BorderColor and BorderSize. But the border doesn't shows up, even with BorderStyle set to None. Here is my code:

Imports System.Windows.Forms
Imports System.Drawing
Imports System.ComponentModel


Public Class BorderedTextBox
    Inherits TextBox

    Dim BColor As Color = Color.Black
    Dim BSize As Double = 1.0

    Public Property BorderColor As Color
        Get
            Return BColor
        End Get
        Set(value As Color)
            BColor = value
        End Set
    End Property



    Public Property BorderSize As Double
        Get
            Return BSize
        End Get
        Set(value As Double)
            BSize = value
        End Set
    End Property

    Public Sub New()
        SetStyle(ControlStyles.UserPaint, True)

    End Sub

    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)

        Dim g As Graphics = e.Graphics

        Dim pen As New Pen(BColor, BSize)
        g.DrawRectangle(pen, New Rectangle(Me.Location, Me.Size))
        pen.Dispose()

        MyBase.OnPaint(e)
    End Sub

End Class

来源:https://stackoverflow.com/questions/24590983/drawing-rectangle-around-custom-textbox-control

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