Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Change caret size and blink rate

Total Hit ( 3946)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


You can alter the size of the caret (this is the name of the cursor within text boxes, not to be confused with the mouse cursor), for instance to ease visibility on notebook computers, or to signal that the text box is in overwrite mode. All you need is a couple of API functions:

Click here to copy the following block
Declare Function CreateCaret Lib "user32" (ByVal hWnd As Long, _
  ByVal hBitmap As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Declare Function ShowCaret Lib "user32" (ByVal hWnd As Long) As Long
Declare Function SetCaretBlinkTime Lib "user32" (ByVal wMSeconds As Long) As _
  Long
Declare Function GetCaretBlinkTime Lib "user32" () As Long

Sub ShowCustomCaret(ByVal width As Integer, ByVal height As Integer)
  On Error Resume Next
  With Screen.ActiveForm.ActiveControl
    CreateCaret .hWnd, 0, width, height
    ShowCaret .hWnd
  End With
End Sub

The second argument to CreateCaret is the handle of a bitmap, a feature that is not used in the above routine. The best place to call the ShowCustomCaret procedure is from within the GotFocus event of a text box:

Click here to copy the following block
Sub Text1_GotFocus()
  ' show a block cursor
  ShowCustomCaret 6, 14
End Sub

Unfortunately, Visual Basic tends to restore the default caret each time a text box gets the input focus, so we should insert a call to ShowCustomCaret routine in the GotFocus of all the text boxes on the form. This won't suffice, however, if the user switches to another application and then back to this form, because in that case no event is fired and we have no chance to re-enforce our custom cursor.
There are two more API functions that deal with carets: GetCaretBlinkTime returns the blink rate of the caret in milliseconds, while SetCaretBlinkTime can change it. Please note, however, that the caret is a shared resource, so you should always restore the blink rate to the original value in the Unload event of the form.





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 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.