Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Exposing textbox bordercolor
Message
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Divers
Thread ID:
00762583
Message ID:
00762594
Vues:
11
Hi Erik,

Here is the code to create a subclassed Textbox that sets the bordercolor to red. You need to override the WndProc method and handle the WM_NCPAINT message.
Imports System.Runtime.InteropServices

Public Class MyTextbox
    Inherits TextBox

    <DllImport("user32.dll")> _
    Public Shared Function GetWindowDC(ByVal hWnd As IntPtr) As IntPtr
    End Function

    <DllImport("user32.dll")> _
    Public Shared Function ReleaseDC(ByVal hWnd As IntPtr, ByVal hDC As IntPtr) As Integer
    End Function

    Protected Overrides Sub WndProc(ByRef m As Message)
        Const WM_NCPAINT As Integer = &H85
        If m.Msg = WM_NCPAINT Then
            Dim hDC As IntPtr = GetWindowDC(m.HWnd)
            Dim graph As Graphics = Graphics.FromHdc(hDC)
            Dim pen1 As New Pen(Color.Red)
            Dim pen2 As New Pen(SystemColors.Window)

            Dim width As Integer = Bounds.Width - 1
            Dim height As Integer = Bounds.Height - 1
            graph.DrawRectangle(pen1, 0, 0, width, height)
            graph.DrawRectangle(pen2, 1, 1, width - 2, height - 2)

            pen1.Dispose()
            pen2.Dispose()
            graph.Dispose()
            ReleaseDC(m.HWnd, hDC)

            m.Result = IntPtr.Zero
        Else
            MyBase.WndProc(m)
        End If
    End Sub 'WndProc
End Class
>hi,
>vb.net textbox control does not have a "bordercolor" property in it. is there a way for me to change the border color?
>-TIA
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform