Guest User

Untitled

a guest
Jul 18th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 5.13 KB | None | 0 0
  1. <DefaultEvent("TextChanged")> _
  2. Class GhostTextBox
  3.     Inherits ThemeControl154
  4.  
  5.     Public Shadows Event KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs)
  6.  
  7.     Sub OnBaseKeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs)
  8.         RaiseEvent KeyPress(sender, e)
  9.     End Sub
  10.  
  11.     Private _TextAlign As HorizontalAlignment = HorizontalAlignment.Left
  12.     Property TextAlign() As HorizontalAlignment
  13.         Get
  14.             Return _TextAlign
  15.         End Get
  16.         Set(ByVal value As HorizontalAlignment)
  17.             _TextAlign = value
  18.             If Base IsNot Nothing Then
  19.                 Base.TextAlign = value
  20.             End If
  21.         End Set
  22.     End Property
  23.     Private _MaxLength As Integer = 32767
  24.     Property MaxLength() As Integer
  25.         Get
  26.             Return _MaxLength
  27.         End Get
  28.         Set(ByVal value As Integer)
  29.             _MaxLength = value
  30.             If Base IsNot Nothing Then
  31.                 Base.MaxLength = value
  32.             End If
  33.         End Set
  34.     End Property
  35.     Private _ReadOnly As Boolean
  36.     Property [ReadOnly]() As Boolean
  37.         Get
  38.             Return _ReadOnly
  39.         End Get
  40.         Set(ByVal value As Boolean)
  41.             _ReadOnly = value
  42.             If Base IsNot Nothing Then
  43.                 Base.ReadOnly = value
  44.             End If
  45.         End Set
  46.     End Property
  47.     Private _UseSystemPasswordChar As Boolean
  48.     Property UseSystemPasswordChar() As Boolean
  49.         Get
  50.             Return _UseSystemPasswordChar
  51.         End Get
  52.         Set(ByVal value As Boolean)
  53.             _UseSystemPasswordChar = value
  54.             If Base IsNot Nothing Then
  55.                 Base.UseSystemPasswordChar = value
  56.             End If
  57.         End Set
  58.     End Property
  59.     Private _Multiline As Boolean
  60.     Property Multiline() As Boolean
  61.         Get
  62.             Return _Multiline
  63.         End Get
  64.         Set(ByVal value As Boolean)
  65.             _Multiline = value
  66.             If Base IsNot Nothing Then
  67.                 Base.Multiline = value
  68.  
  69.                 If value Then
  70.                     LockHeight = 0
  71.                     Base.Height = Height - 11
  72.                 Else
  73.                     LockHeight = Base.Height + 11
  74.                 End If
  75.             End If
  76.         End Set
  77.     End Property
  78.     Overrides Property Text As String
  79.         Get
  80.             Return MyBase.Text
  81.         End Get
  82.         Set(ByVal value As String)
  83.             MyBase.Text = value
  84.             If Base IsNot Nothing Then
  85.                 Base.Text = value
  86.             End If
  87.         End Set
  88.     End Property
  89.     Overrides Property Font As Font
  90.         Get
  91.             Return MyBase.Font
  92.         End Get
  93.         Set(ByVal value As Font)
  94.             MyBase.Font = value
  95.             If Base IsNot Nothing Then
  96.                 Base.Font = value
  97.                 Base.Location = New Point(3, 5)
  98.                 Base.Width = Width - 6
  99.  
  100.                 If Not _Multiline Then
  101.                     LockHeight = Base.Height + 11
  102.                 End If
  103.             End If
  104.         End Set
  105.     End Property
  106.  
  107.     Protected Overrides Sub OnCreation()
  108.         If Not Controls.Contains(Base) Then
  109.             Controls.Add(Base)
  110.         End If
  111.     End Sub
  112.  
  113.     Private Base As TextBox
  114.     Sub New()
  115.         Base = New TextBox
  116.  
  117.         Base.Font = Font
  118.         Base.Text = Text
  119.         Base.MaxLength = _MaxLength
  120.         Base.Multiline = _Multiline
  121.         Base.ReadOnly = _ReadOnly
  122.         Base.UseSystemPasswordChar = _UseSystemPasswordChar
  123.  
  124.         Base.BorderStyle = BorderStyle.None
  125.  
  126.         Base.Location = New Point(5, 5)
  127.         Base.Width = Width - 10
  128.  
  129.         If _Multiline Then
  130.             Base.Height = Height - 11
  131.         Else
  132.             LockHeight = Base.Height + 11
  133.         End If
  134.  
  135.         AddHandler Base.TextChanged, AddressOf OnBaseTextChanged
  136.         AddHandler Base.KeyDown, AddressOf OnBaseKeyDown
  137.         AddHandler Base.KeyPress, AddressOf OnBaseKeyPress
  138.  
  139.         SetColor("Text", Color.White)
  140.         SetColor("Back", 0, 0, 0)
  141.         SetColor("Border1", Color.Black)
  142.         SetColor("Border2", 90, 90, 90)
  143.     End Sub
  144.  
  145.     Private C1 As Color
  146.     Private P1, P2 As Pen
  147.  
  148.     Protected Overrides Sub ColorHook()
  149.         C1 = GetColor("Back")
  150.  
  151.         P1 = GetPen("Border1")
  152.         P2 = GetPen("Border2")
  153.  
  154.         Base.ForeColor = GetColor("Text")
  155.         Base.BackColor = C1
  156.     End Sub
  157.  
  158.     Protected Overrides Sub PaintHook()
  159.         G.Clear(C1)
  160.  
  161.         DrawBorders(P1, 1)
  162.         DrawBorders(P2)
  163.     End Sub
  164.     Private Sub OnBaseTextChanged(ByVal s As Object, ByVal e As EventArgs)
  165.         Text = Base.Text
  166.     End Sub
  167.     Private Sub OnBaseKeyDown(ByVal s As Object, ByVal e As KeyEventArgs)
  168.         If e.Control AndAlso e.KeyCode = Keys.A Then
  169.             Base.SelectAll()
  170.             e.SuppressKeyPress = True
  171.         End If
  172.     End Sub
  173.     Protected Overrides Sub OnResize(ByVal e As EventArgs)
  174.         Base.Location = New Point(5, 5)
  175.         Base.Width = Width - 10
  176.  
  177.         If _Multiline Then
  178.             Base.Height = Height - 11
  179.         End If
  180.  
  181.  
  182.         MyBase.OnResize(e)
  183.     End Sub
  184.  
  185. End Class
Add Comment
Please, Sign In to add comment