Re: Still need help on Rich Text Box
From: David Youngblood (dwy_at_flash.net)
Date: 02/04/05
- Next message: MikeB: "Re: Copy File from Web Site"
- Previous message: Rick Rothstein: "Re: Precision problem in VBasic 6"
- In reply to: Les: "Still need help on Rich Text Box"
- Next in thread: Les: "Re: Still need help on Rich Text Box"
- Reply: Les: "Re: Still need help on Rich Text Box"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 4 Feb 2005 11:20:10 -0600
A solution that should work is to place the rtb inside a picturebox and make the
rtb larger than the widest text line. Set the rtb borders to none and scrollbars
off. And add scrollbars to the picturebox. I'm not going to write it for, but
you should be able to find an example by searching the archives for "scrollable
viewport".
David
"Les" <vb4@prodigy.net> wrote in message
news:uVctBMpCFHA.3924@TK2MSFTNGP15.phx.gbl...
> Sorry for running this again but I still have not been able to make this RTB
> perform the way I want it to. In the last post I included the code snippet
> but I dont believe anyone here had run it to observe the problem I am
> having. Following is the code snippet along with just 5 lines which have
> been taken out of the text file where it is stored.
>
> Code snippet follow:
>
> 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 Declare Function GetCaretPos Lib "user32" ( _
> lpPoint As POINTAPI) As Long
>
> Private Type POINTAPI
> x As Long
> y As Long
> End Type
>
> Private Const EM_LINELENGTH = &HC1
> Private Const EM_SETSEL = &HB1
> Private Const EM_CHARFROMPOS = &HD7
>
> Private m_fDisable As Boolean
> Private m_fMouse As Boolean
>
> Private Sub Command1_Click()
> Print rtb1.SelText
> rtb1.SetFocus
> End Sub
>
> Private Sub Form_Load()
> Dim t As String
> rtb1.HideSelection = False
> rtb1.Locked = True
> t =
> "100111111010010111011011101100011001011101001101000110101000001000111111101
> 001100000000100000001000000000000000000000000000000000000000000000000" &
> vbCRLF
> t = t &
> "111010010110010111000011001011100001000011101000000100000011100000001000000
> 100000010000001000000100000010000000000000" & vbCRLF
> t = t &
> "101011011010101110111001100100011001011100001000100101000000100000011110000
> 001000000100000010000001000000100000010000001000000" & vbCRLF
> t = t &
> "110111010100101010000101001101110101000111101000110100100111000111001100000
> 0110010111001110110001001101001100101011101101001111101101000010000010001001
> 11000100100001010100000000000000000000011100001000000001100000000000000000"
> & vbCRLF
> t = t &
> "101101101100110110000111110011001110100110101100101001000011001011100111011
> 0001101101001111101000010000011010000001000001111110000011111001000000100000
> 00000000000000000000000000000"
> rtb1.text = t
> End Sub
>
> Private Sub Form_Activate()
> rtb1.Refresh
> Call rtb1_SelChange
> End Sub
>
> Private Sub rtb1_SelChange()
> Dim pt As POINTAPI
> Dim iOffset As Long
> Dim iLength As Long
> If m_fMouse Or m_fDisable Then Exit Sub
> m_fDisable = True
> If GetCaretPos(pt) Then
> pt.x = 1
> iOffset = SendMessage(rtb1.hwnd, EM_CHARFROMPOS, 0&, _
> ByVal VarPtr(pt))
> iLength = SendMessage(rtb1.hwnd, EM_LINELENGTH, _
> ByVal iOffset, ByVal 0&)
> SendMessage rtb1.hwnd, EM_SETSEL, iOffset, _
> ByVal iOffset + iLength
> End If
> m_fDisable = False
> End Sub
>
> Private Sub rtb1_KeyDown(KeyCode As Integer, Shift As Integer)
> If (KeyCode = vbKeyLeft) Or (KeyCode = vbKeyRight) Then
> If Not m_fDisable Then
> KeyCode = 0
> End If
> ElseIf KeyCode = vbKeyHome Then
> rtb1.SelStart = 0
> ElseIf KeyCode = vbKeyEnd Then
> rtb1.SelStart = Len(rtb1.Text)
> End If
> End Sub
>
> Private Sub rtb1_MouseDown(Button As Integer, Shift As Integer, x As Single,
> y As Single)
> m_fMouse = True
> End Sub
>
> Private Sub rtb1_MouseUp(Button As Integer, Shift As Integer, x As Single, y
> As Single)
> m_fMouse = False
> End Sub
>
>
> My first thought is do you think since I have both the horizontal and
> vertical scroll bars on in the richtextbox that this could have an affect on
> the scrolling of these rows?? It seems that the above code works fine until
> if you use only the vertical scroll bar but has a problem when using both
> vert and horz scrollbars?
> Whatever this problem is it appears to exist when you select a line where
> the text is longer then the
> width of the rtb and you have horizontal scrollbars active.
>
> Atleast that is my initial finding so far.
> Any thoughts.
>
> Off the subject why doesnt the rtb from the scroll bar point of view work
> like a regular text box. With
> a text box the scrollbars are implicitly set to handle the widest text
> line??
>
>
> Thanks
>
>
- Next message: MikeB: "Re: Copy File from Web Site"
- Previous message: Rick Rothstein: "Re: Precision problem in VBasic 6"
- In reply to: Les: "Still need help on Rich Text Box"
- Next in thread: Les: "Re: Still need help on Rich Text Box"
- Reply: Les: "Re: Still need help on Rich Text Box"
- Messages sorted by: [ date ] [ thread ]