Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rich TextBox

Status
Not open for further replies.

Normally

IS-IT--Management
May 13, 2008
22
BB
hello Everyone
Can you show me how to hide Caret in Rich TextBox?
 
Like so:

Code:
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 RichTextBox1_Change()
    HideCaret RichTextBox1.hwnd
End Sub

[wink]
 
hi three57m
that did not work. No editing is to be done on rtb.
 
Were you hoping that eliminating the caret will prevent any editing (in which case you might perhaps want to rephrase your original quation so that we understand your actual goal), or are you handling that seperately? If so, how are you doing it?

 
hi strongm
i have array of rtb in which no editing takes place. I want that when i click on a rtb element i do not see caret.
 
My question remains: how are you stopping the editing? Or is it your assumption that stopping the caret will prevent editing? In other words is your actual question "How do I stop people editing an RTB?
 
I am stopping the editing by setting locked to true.
 
Excellent. So what you are trying to achieve is the elimination of any (graphical) suggestion that the user can interact with the RTB. And you don't want to use the Enabled property because it changes the appearance of the RTB ...

There are a couple of ways of achieving this. Here's one that uses the Text Object Model interface. You'll need to add a reference to tom to your project

Code:
[blue]Option Explicit
 
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_USER = &H400&
Private Const EM_GETOLEINTERFACE = (WM_USER + 60)

Public Function FreezeRTB(TargetRTB As RichTextBox, FreezeIt As Boolean) As Long
 
    Dim myIUnknown As Object
    Dim TextRange As ITextRange
    Dim tomDoc As ITextDocument
    Dim result As Long
    
    SendMessage TargetRTB.hwnd, EM_GETOLEINTERFACE, 0&, myIUnknown
    Set tomDoc = myIUnknown
    
    TargetRTB.Locked = FreezeIt
    If FreezeIt Then
        FreezeRTB = tomDoc.Freeze
    Else
        FreezeRTB = tomDoc.Unfreeze
    End If
    
End Function[/blue]
 
i'll tyr that wwhen i get home. But would i be able to execute click event on the rtb after without seeing caret?
 
i'll try that when i get home. But would i be able to execute click event on the rtb after without seeing caret?
 
hi strongm
i'll try that when i get home. But would i be able to execute click event on the rtb afterwards without seeing caret?
 
hi strongm
i'll try that when i get home. But would i be able to execute click event on the rtb afterwards without seeing caret? What is "Text Object Model Interface" and where can i find it? getting error user-defined type not defined- var textrange & tomdoc
 
As I said,"You'll need to add a reference to tom to your project". To do this select the Project menu, and click 'References'. In the resulting dialog scroll down until you find 'tom'. Click the checkbox next to it so that it is ticked, then click on OK. The necessary reference is now added, and the error messages will no longer appear (BTW, you can safely delete [blue][tt]Dim TextRange As ITextRange[/tt][/blue] from the example; it isn't needed)

And yes, the RTB's click event still works
 
add two commandbuttons to test
Code:
Private Declare Function LockWindowUpdate Lib "USER32" (ByVal hwndLock As Long) As Long

Private Sub Command1_Click()
    LockWindowUpdate RichTextBox1.hWnd
End Sub

Private Sub Command2_Click()
    LockWindowUpdate 0
End Sub
 
Technically, we probably shouldn't use LockWindowUpdate like that. It is best used for very brief locking of a window rather than the extended period of locking that it is pretty clear is necessary here (some - such as Raymond Chen - would go further, and almost ban it's use completely). If you want to go the API route then I'd recommend sending an apprpriate WM_SETREDRAW message to the window instead
 
hi strongm
I forgot to say i'm using control array of rtb. will there be a diff? when i move mouse over rtb it changes color. with tom the color does not revert to old color when i move over another element of array.
 
I was working on the assumption that you wanted to "[eliminate] any (graphical) suggestion that the user can interact with the RTB". As you are now learning it is quite important to fully state your problem before we can give a full solution.

In this case, all you should need to do is briefly, in the routine that changes the colour, unfreeze the rtb before making the colour change, and then immediately refreeze afterwards
 
hi strongm
That does not work. Suppose i were to go about it using labels where each row would consist of say 10 labels where labels 0-8 would be a string & label 9 an integer.
how would my data structure be?
ex :
row(0) ==> HELLO 25
row(1) HOW 3
row(3) BASICALLY 45

bearing in mind that each letter is a label
 
>That does not work

In what way doesn't it work? It certainly ought to.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top