|
|
|
Click here to copy the following block |
Option Explicit
Private Declare Function CreateCaret Lib "user32" (ByVal hWnd As Long, _ ByVal hBitmap As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long Private Declare Function ShowCaret Lib "user32" (ByVal hWnd As Long) As Long
Private m_OverwriteMode As Boolean
Private WithEvents HookedForm As Form
Private ActiveControl As Control
Private m_BlockCaret As Boolean
Public Property Get Form() As Form Set Form = HookedForm End Property
Public Property Set Form(ByVal newValue As Form) Set HookedForm = newValue If Not (HookedForm Is Nothing) Then HookedForm.KeyPreview = True End If End Property
Public Property Get OverwriteMode() As Boolean CheckActiveControl OverwriteMode = m_OverwriteMode End Property
Public Property Let OverwriteMode(ByVal newValue As Boolean) m_OverwriteMode = newValue UpdateCaret End Property
Property Get BlockCaret() As Boolean BlockCaret = m_BlockCaret End Property
Property Let BlockCaret(ByVal newValue As Boolean) m_BlockCaret = newValue UpdateCaret End Property
Public Sub UpdateCaret() On Error Resume Next If Not CheckActiveControl Then ElseIf OverwriteMode And BlockCaret Then CreateCaret ActiveControl.hWnd, 0, 6, 14 ShowCaret ActiveControl.hWnd Else CreateCaret ActiveControl.hWnd, 0, 1, 14 ShowCaret ActiveControl.hWnd End If End Sub
Private Function CheckActiveControl() As Boolean If Not Form.ActiveControl Is ActiveControl Then Set ActiveControl = Form.ActiveControl OverwriteMode = False End If On Error Resume Next CheckActiveControl = (ActiveControl.SelLength >= 0) End Function
Private Sub HookedForm_KeyPress(KeyAscii As Integer) On Error Resume Next If Not CheckActiveControl Then ElseIf m_OverwriteMode And KeyAscii >= 32 And ActiveControl.SelLength = 0 _ Then If Mid$(ActiveControl.Text, ActiveControl.SelStart + 1, 1) <> vbCr Then ActiveControl.SelLength = 1 End If End If End Sub
Private Sub HookedForm_KeyDown(KeyCode As Integer, Shift As Integer) If CheckActiveControl Then If KeyCode = 45 And Shift = 0 Then OverwriteMode = Not OverwriteMode End If End If End Sub
Private Sub HookedForm_Activate() If CheckActiveControl Then UpdateCaret End Sub |
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|