Solved

Disable blinking text cursor on form!

Posted on 2000-03-22
15
646 Views
Last Modified: 2008-01-09
This is so basic, I'm even scared to ask.

I have a form, on the form there's a number of textfields, and when I run the program there's a blinking curser on one of those fields.  How do I get rid of that?   I tried something that slows the rate down, but the cursor is still there, I want it gone!

Thanks!
0
Comment
Question by:prosit
  • 8
  • 4
  • 3
15 Comments
 
LVL 32

Accepted Solution

by:
Erick37 earned 50 total points
ID: 2646383
If the user is not required to enter text, then use a Label control.

If the user is able to enter text, do you want a visible, non-blinking cursor?
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2646392
Add the following to the declarations section:

   Private Declare Function ShowCaret Lib "user32" (ByVal hwnd As Long) As Long

Then in the click and gotfocus events of the textbox, do this:

   Private Sub Text1_Click()
       HideCaret Text1.hwnd
   End Sub
   Private Sub Text1_GotFocus()
       HideCaret Text1.hwnd
   End Sub


Cheers!®©
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2646399
By the way... an easy question is usually 50 points... ;-)


Cheers!®©
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2646404
OOPS!!!!

That declaration should have been:

   Declare Function HideCaret Lib "user32" Alias "HideCaret" (ByVal hwnd As Long) As Long

not ShowCaret... Sorry...


Cheers!®©
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2646446
Since hiding and showing the caret is cumulative, shouldn't you do:

Option Explicit

Private Declare Function ShowCaret Lib "user32" _
    (ByVal hwnd As Long) As Long
Private Declare Function HideCaret Lib "user32" _
    (ByVal hwnd As Long) As Long

Private Sub Text1_GotFocus()
    HideCaret Text1.hwnd
End Sub

Private Sub Text1_LostFocus()
    ShowCaret Text1.hwnd
End Sub

(Assuming Funch does not want to see the cursor at all.)
0
 
LVL 2

Author Comment

by:prosit
ID: 2646486
Adjusted points from 10 to 50
0
 
LVL 2

Author Comment

by:prosit
ID: 2646487
1. I like Eric's answer better, I knew it was simple.

2. If you don't want to answer with the points given, don't.  It was a very simple solution and Eric17 even corrected yours.

But alright, Eric17 you get the 50 point.

Tax
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Author Comment

by:prosit
ID: 2646492
Thanks, good job dude!

I don't need input, it's just a counter.

I knew it was a stupid error!

Tax
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2646516
Erick37

Although HideCaret is cumulative as an API, it is not cumlative in VB.  Here is an example of what I mean...

Put a textbox and a commandbutton on a form and then put the following code in the declarations section:

    Private Declare Function HideCaret Lib "user32" (ByVal hwnd As Long) As Long
    Private Sub Command1_Click()
        HideCaret Text1.hwnd
    End Sub


Set the tabstop of the textbox to 0, then run the program. Notice that the textbox has a caret.  Click the commandbutton to call HideCaret and the caret goes away... Click the button 5 more times, then click the textbox and the caret shows without calling ShowCaret...


Cheers!®©
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2646523
BTW, this is why you have to call HideCaret in the click event... Because VB automatically releases the hide and shows the caret again...


Cheers!®©
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2646562
funch,

1)  >> If you don't want to answer with the points given, don't

Don't get so bent out of shape.  I answered your question even though it was at the 10 point level. I was merely pointing out the EE standard for asking questions...

2)  >> Eric17 even corrected yours.

"Erick37" did not correct my post, as I've explained in the previous post.


3)  You specifically asked how to get rid of the cursor from a textfield.  The code I gave you did that without replacing the control you were using.


4)  Good-luck!

0
 
LVL 32

Expert Comment

by:Erick37
ID: 2646597
mcrider,
I see your point, VB does act differently.

But why code HideCaret in the click event?  When the TextBox is clicked, it fires the GotFocus event.
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2646652
Erick37,

Because you can get the the text box 2 ways... either by:

  * Tabbing to the textbox - in this event, the click event doesn't fire however the caret is enabled when you have focus.

  * Clicking on the textbox - yes, when you click on the textbox the FIRST time, the GotFocus event fires then the click event fires, however, if you already have focus, and you click in another area of the same textbox, only the click event fires... If you already have focus and click somewhere else in the same textbox, VB will fire the ShowCaret for you again, so the click event will hide it.


Cheers!®©

0
 
LVL 32

Expert Comment

by:Erick37
ID: 2646683
I'm testing this in VB5, and without any code in the Click event, the caret is not showing, even after multiple clicks.  Perhaps a version difference?
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2646736
I'm working on my NT system today... I just tried it on my 95 system... Click event is not necessary on 95, but is on NT...  Good catch!


Cheers!®©
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
DIR issue 7 51
Need VBS version of Excel date conversion 4 65
Excel VBA, find a string in a column, update a cell 7 67
Spell Check in VB6 13 99
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now