Created
May 30, 2022 03:36
-
-
Save gekka/d06d9dc6e166ba2834237e02d7f50f1d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Class TextBoxEx | |
Inherits TextBox | |
Sub New() | |
If Tool.IsWin11 Then | |
Me.BorderStyle = BorderStyle.FixedSingle | |
End If | |
End Sub | |
Protected Overrides Sub OnBorderStyleChanged(e As EventArgs) | |
If Tool.IsWin11 AndAlso Me.BorderStyle <> BorderStyle.FixedSingle Then | |
Me.BorderStyle = BorderStyle.FixedSingle | |
End If | |
MyBase.OnBorderStyleChanged(e) | |
End Sub | |
Private Enum WM | |
WM_KILLFOCUS = 8 | |
WM_PAINT = &HF | |
WM_MOUSEMOVE = &H200 | |
End Enum | |
Protected Overrides Sub WndProc(ByRef m As Message) | |
MyBase.WndProc(m) | |
If Tool.IsWin11 Then | |
Select Case CType(m.Msg, WM) | |
Case WM.WM_KILLFOCUS | |
Case WM.WM_PAINT | |
DrawBorder() | |
End Select | |
End If | |
End Sub | |
Private Sub DrawBorder() | |
If Me.BorderStyle <> BorderStyle.FixedSingle Then | |
Return | |
End If | |
Dim pen As Pen | |
Dim f As Form = Me.FindForm | |
If f IsNot Nothing AndAlso f.ActiveControl Is Me AndAlso f.ContainsFocus Then | |
pen = New Pen(SystemBrushes.Highlight, 1) | |
Else | |
Dim pos As Point = PointToClient(Cursor.Position) | |
If 0 <= pos.X AndAlso pos.X < Me.Width AndAlso 0 <= pos.Y AndAlso pos.Y < Me.Height Then | |
pen = New Pen(Color.Black, 1) | |
Else | |
pen = New Pen(Color.FromArgb(122, 122, 122), 1) | |
End If | |
End If | |
Using g As Graphics = Me.CreateGraphics() | |
g.DrawRectangle(pen, 0, 0, Me.Width - 1, Me.Height - 1) | |
End Using | |
pen.Dispose() | |
End Sub | |
End Class | |
Class Tool | |
Public Shared ReadOnly Property IsWin11 As Boolean | |
Get | |
Return _IsWin11 | |
End Get | |
End Property | |
Private Shared ReadOnly Property _IsWin11 As Boolean | |
Shared Sub New() | |
_IsWin11 = (11 = System.Environment.OSVersion.Version.Major) | |
Dim cv = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion") | |
Dim currentBuild As Integer | |
If Integer.TryParse(cv.GetValue("CurrentBuild"), currentBuild) Then | |
_IsWin11 = _IsWin11 Or (currentBuild >= 22000) | |
End If | |
End Sub | |
End Class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment