home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Begin VB.UserControl DJField
- ClientHeight = 390
- ClientLeft = 0
- ClientTop = 0
- ClientWidth = 1395
- ScaleHeight = 390
- ScaleWidth = 1395
- Begin VB.TextBox Text1
- BeginProperty Font
- Name = "MS Sans Serif"
- Size = 9.75
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 315
- Left = 45
- TabIndex = 0
- Text = "Text1"
- Top = 30
- Width = 1215
- End
- Attribute VB_Name = "DJField"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = True
- Attribute VB_PredeclaredId = False
- Attribute VB_Exposed = True
- 'This is an example control project of using a vtable binding class
- 'to improve execution speed. See test form in project1 for speed
- 'testing procedure. This is a case where the enumerated data type (vForceCase)
- 'does not cause an error.
- Implements iFastField
- Option Explicit
- Private m_Text As String
- Private m_Size As Integer
- Private m_ForceNumeric As Boolean
- Private m_ForceCase As vForceCase
- Private m_ForceString As String
- Private m_LastKey As String
- Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
- (ByVal hWnd As Long, ByVal nIndex As Long) As Long
- Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
- (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
- Private Const GWL_STYLE = (-16)
- Enum vForceCase
- [Default] = 0
- [Upper Case] = 1
- [Lower Case] = 2
- End Enum
- 'Event Declarations:
- Event KeyPress(KeyAscii As Integer) 'MappingInfo=Text1,Text1,-1,KeyPress
- Attribute KeyPress.VB_Description = "Occurs when the user presses and releases an ANSI key."
- Private Sub Text1_Change()
- If Len(m_ForceString) > 0 Then
- If InStr((LCase(m_ForceString) & vbBack & vbNullString & vbCr), LCase(m_LastKey)) = 0 Then
- Text = m_Text
- Text1.SelStart = m_Size
- Exit Sub
- End If
- End If
- If Len(Text1) > m_Size Then
- Text = m_Text
- Text1.SelStart = m_Size
- Exit Sub
- End If
- m_Text = Text1
- End Sub
- Private Sub Text1_KeyPress(KeyAscii As Integer)
- m_LastKey = Chr(KeyAscii)
- RaiseEvent KeyPress(KeyAscii)
- End Sub
- Public Property Get Size() As Integer
- Size = m_Size
- End Property
- Public Property Let Size(ByVal New_Size As Integer)
- m_Size = New_Size
- End Property
- Public Property Get Text() As String
- Attribute Text.VB_UserMemId = 0
- Attribute Text.VB_MemberFlags = "200"
- Text = m_Text
- End Property
- Public Property Let Text(ByVal New_text As String)
- Text1 = New_text
- m_Text = New_text
- End Property
- Private Sub Text1_GotFocus()
- Text1.SelStart = Len(Text1)
- End Sub
- Private Sub UserControl_InitProperties()
- m_Size = Len(Extender.Name)
- Me.Text = Extender.Name
- End Sub
- Private Sub UserControl_Resize()
- With UserControl
- Text1.Move 0, 0, .ScaleWidth, .ScaleHeight
- End With
- End Sub
- Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
- With PropBag
- ForceString = .ReadProperty("ForceString", vbNullString)
- ForceNumeric = .ReadProperty("ForceNumeric", False)
- ForceCase = .ReadProperty("ForceCase", [Default])
- Size = .ReadProperty("Size", Len(Extender.Name))
- Text = .ReadProperty("Text", Extender.Name)
- SelLength = .ReadProperty("SelLength", 0)
- SelStart = .ReadProperty("SelStart", 0)
- SelText = .ReadProperty("SelText", "")
- Locked = .ReadProperty("Locked", False)
- Enabled = .ReadProperty("Enabled", True)
- End With
- End Sub
- Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
- With PropBag
- Call .WriteProperty("ForceString", m_ForceString, vbNullString)
- Call .WriteProperty("ForceCase", m_ForceCase, [Default])
- Call .WriteProperty("ForceNumeric", m_ForceNumeric, False)
- Call .WriteProperty("Text", m_Text)
- Call .WriteProperty("Size", m_Size)
- Call .WriteProperty("SelLength", Text1.SelLength, 0)
- Call .WriteProperty("SelStart", Text1.SelStart, 0)
- Call .WriteProperty("SelText", Text1.SelText, "")
- Call .WriteProperty("Locked", Text1.Locked, False)
- Call .WriteProperty("Enabled", Text1.Enabled, True)
- End With
- End Sub
- 'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
- 'MappingInfo=Text1,Text1,-1,SelLength
- Public Property Get SelLength() As Long
- Attribute SelLength.VB_Description = "Returns/sets the number of characters selected."
- SelLength = Text1.SelLength
- End Property
- Public Property Let SelLength(ByVal New_SelLength As Long)
- Text1.SelLength() = New_SelLength
- PropertyChanged "SelLength"
- End Property
- 'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
- 'MappingInfo=Text1,Text1,-1,SelStart
- Public Property Get SelStart() As Long
- Attribute SelStart.VB_Description = "Returns/sets the starting point of text selected."
- SelStart = Text1.SelStart
- End Property
- Public Property Let SelStart(ByVal New_SelStart As Long)
- Text1.SelStart() = New_SelStart
- PropertyChanged "SelStart"
- End Property
- 'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
- 'MappingInfo=Text1,Text1,-1,SelText
- Public Property Get SelText() As String
- Attribute SelText.VB_Description = "Returns/sets the string containing the currently selected text."
- SelText = Text1.SelText
- End Property
- Public Property Let SelText(ByVal New_SelText As String)
- Text1.SelText() = New_SelText
- PropertyChanged "SelText"
- End Property
- 'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
- 'MappingInfo=Text1,Text1,-1,Locked
- Public Property Get Locked() As Boolean
- Attribute Locked.VB_Description = "Determines whether a control can be edited."
- Locked = Text1.Locked
- End Property
- Public Property Let Locked(ByVal New_Locked As Boolean)
- Text1.Locked() = New_Locked
- PropertyChanged "Locked"
- End Property
- 'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
- 'MappingInfo=UserControl,UserControl,-1,hWnd
- Public Property Get hWnd() As Long
- Attribute hWnd.VB_Description = "Returns a handle (from Microsoft Windows) to an object's window."
- hWnd = UserControl.hWnd
- End Property
- 'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
- 'MappingInfo=Text1,Text1,-1,Enabled
- Public Property Get Enabled() As Boolean
- Attribute Enabled.VB_Description = "Returns/sets a value that determines whether an object can respond to user-generated events."
- Enabled = Text1.Enabled
- End Property
- Public Property Let Enabled(ByVal New_Enabled As Boolean)
- Text1.Enabled() = New_Enabled
- PropertyChanged "Enabled"
- End Property
- Public Property Get ForceNumeric() As Boolean
- ForceNumeric = m_ForceNumeric
- End Property
- Public Property Let ForceNumeric(ByVal Force As Boolean)
- Dim style As Long
- Const ES_NUMBER = &H2000
- m_ForceNumeric = Force
- ' get current style
- style = GetWindowLong(Text1.hWnd, GWL_STYLE)
- If Force Then
- style = style Or ES_NUMBER
- Else
- style = style And Not ES_NUMBER
- End If
- ' enforce new style
- SetWindowLong Text1.hWnd, GWL_STYLE, style
- PropertyChanged "ForceNumeric"
- End Property
- Public Property Get ForceCase() As vForceCase
- ForceCase = m_ForceCase
- End Property
- Public Property Let ForceCase(ByVal New_Case As vForceCase)
- Dim style As Long
- If m_ForceNumeric Then ForceNumeric = False
- Const ES_UPPERCASE = &H8&
- Const ES_LOWERCASE = &H10&
- m_ForceCase = New_Case
- ' get current style
- style = GetWindowLong(Text1.hWnd, GWL_STYLE)
- Select Case New_Case
- Case [Default]
- style = style And Not (ES_UPPERCASE Or ES_LOWERCASE)
- Case [Upper Case]
- style = style Or ES_UPPERCASE
- Case [Lower Case]
- style = style Or ES_LOWERCASE
- End Select
- ' enforce new style
- SetWindowLong Text1.hWnd, GWL_STYLE, style
- PropertyChanged "ForceCase"
- End Property
- Public Property Get ForceString() As String
- ForceString = m_ForceString
- End Property
- Public Property Let ForceString(ByVal New_String As String)
- m_ForceString = New_String
- PropertyChanged "ForceString"
- End Property
- Private Property Let iFastField_Enabled(ByVal New_Enabled As Boolean)
- Enabled = New_Enabled
- End Property
- Private Property Get iFastField_Enabled() As Boolean
- iFastField_Enabled = Enabled
- End Property
- Private Property Let iFastField_ForceCase(ByVal New_Case As vForceCase)
- ForceCase = New_Case
- End Property
- Private Property Get iFastField_ForceCase() As vForceCase
- iFastField_ForceCase = ForceCase
- End Property
- Private Property Let iFastField_ForceNumeric(ByVal Force As Boolean)
- ForceNumeric = Force
- End Property
- Private Property Get iFastField_ForceNumeric() As Boolean
- iFastField_ForceNumeric = ForceNumeric
- End Property
- Private Property Let iFastField_ForceString(ByVal New_String As String)
- ForceString = New_String
- End Property
- Private Property Get iFastField_ForceString() As String
- iFastField_ForceString = ForceString
- End Property
- Private Property Get iFastField_hWnd() As Long
- iFastField_hWnd = hWnd
- End Property
- Private Property Let iFastField_Locked(ByVal New_Locked As Boolean)
- Locked = New_Locked
- End Property
- Private Property Get iFastField_Locked() As Boolean
- iFastField_Locked = Locked
- End Property
- Private Property Let iFastField_SelLength(ByVal New_SelLength As Long)
- SelLength = New_SelLength
- End Property
- Private Property Get iFastField_SelLength() As Long
- iFastField_SelLength = SelLength
- End Property
- Private Property Let iFastField_SelStart(ByVal New_SelStart As Long)
- SelStart = New_SelStart
- End Property
- Private Property Get iFastField_SelStart() As Long
- iFastField_SelStart = SelStart
- End Property
- Private Property Let iFastField_SelText(ByVal New_SelText As String)
- SelText = New_SelText
- End Property
- Private Property Get iFastField_SelText() As String
- iFastField_SelText = SelText
- End Property
- Private Property Let iFastField_Size(ByVal New_Size As Integer)
- Size = New_Size
- End Property
- Private Property Get iFastField_Size() As Integer
- iFastField_Size = Size
- End Property
- Private Property Let iFastField_Text(ByVal New_text As String)
- Text = New_text
- End Property
- Private Property Get iFastField_Text() As String
- iFastField_Text = Text
- End Property
-