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?
 
hi strongm
here is code.
i have to click on "FldOne" a few times before it freezes.The caret also gets frozen as well.below is a sample of code.also fldone is not hilighted anymore as i move over new rtb.

Private Sub FldOne_GotFocus(Index As Integer)
Dim R As Long
R = FreezeRTB(FldOne(Index), True)
End Sub

Public Sub ChangeColor(RowNum As Integer, ColNum As Integer)
Dim c As Long
c = FreezeRTB(FldOne(RowNum), False)
Select Case ColNum
Case 0
Hilighted = False
FldOne(RowNum).BackColor = OldCol
FldTwo(RowNum).BackColor = OldCol
Case 1
Hilighted = True
FldOne(RowNum).BackColor = HiCol
FldTwo(RowNum).BackColor = HiCol
End Select
c = FreezeRTB(FldOne(RowNum), True)
End Sub
 
Ah ... actually, that would appear to be a bug - or, at best, undocumented behaviour. Not in your code, but for the RTB. Hmm ...
 
hi strongm
I have reverted to multiline RTB. I put a text box off the form & when rtb gets focus i set focus to text box . Now i don't see caret. I can get number of lines, current line using "Sendmessage" but i cant get text of the current line.
Any idea?
 
>text of the current line. Any idea?

I do indeed. Unfortunatley I'm not really anywhere near a development box today, so it may be a few hours or so before I can provide an example of how we might do this.
 
Om, first of all the poor man's versions. This assumes that each line is seperated by a vbCRLF and that we don't have any softbreaks (i.e a new line forced simply by the fact that the line is too wide for the RTB):
Code:
[blue]Option Explicit

Private Sub Command1_Click()
    RichTextBox1.Text = "hello there" & vbCrLf & "this is a" & vbCrLf & "test to show how" & vbCrLf & "to see what is in selected line"
End Sub

Private Sub RichTextBox1_Click()
    Debug.Print Split(RichTextBox1.Text, vbCrLf)(RichTextBox1.GetLineFromChar(RichTextBox1.SelStart))
End Sub[/blue]
 
And here's the fractionally more complex version that deals with soft and hard breaks using the text object model (meaning that, as advised before, you'll need to add the tom library to your project's references):
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)

Private Sub Command1_Click()
    RichTextBox1.Text = "hello there" & vbCrLf & "this is a" & vbCrLf & "test to show how" & vbCrLf & "to see what is in selected line"
End Sub


Private Sub RichTextBox1_Click()
    Dim myIUnknown As Object
    Dim TextRange As ITextRange
    Dim tomDoc As ITextDocument
    
    SendMessage RichTextBox1.hwnd, EM_GETOLEINTERFACE, 0&, myIUnknown
    Set tomDoc = myIUnknown
    Set TextRange = tomDoc.Selection
    TextRange.Expand tomLine
    Debug.Print TextRange.Text
End Sub[/blue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top