Re: re Rich Text Box
From: Les (vb4_at_prodigy.net)
Date: 01/02/05
- Next message: Rick Rothstein: "Re: re Rich Text Box"
- Previous message: DavidM: "VCL and Delphi?"
- In reply to: Rick Rothstein: "Re: re Rich Text Box"
- Next in thread: Rick Rothstein: "Re: re Rich Text Box"
- Reply: Rick Rothstein: "Re: re Rich Text Box"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 2 Jan 2005 01:47:30 -0500
Hi Rick,
Listen I tested your code and thats basically what I wanted to do however it
acts strange when I setup a Rich Text Box with 20 lines in it. What I mean
the right line gets selected however the list moves with a selection. Try
filling a RTB with 20 lines and select like line 8 and you will see what I
mean. Perhaps this can not be avoided I am not sure. I prefer that the
list in the RTB only moves when I Page up or pgdn or home or end. It should
not move when I am selecting an actaul displayed row.
Any thoughts ?
Other then that excellent!
Thanks
Les
"Rick Rothstein" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in message
news:#9N#JA37EHA.3708@TK2MSFTNGP14.phx.gbl...
> There is a problem using SendKeys "{HOME}+{END}" and trying to program
> the Home and End keys separately (since the SendKeys simulates pressing
> the Home and End keys; hence, you end up in an endless loop). We can
> ditch the SendKeys and use two methods that the RichTextBox provides to
> simulate its action. Here is some code that works with the mouse click
> and the key presses you indicated you wanted to use. However, I made a
> guess that when you said you wanted to use the Home and End keys, that
> you want them to take you directly to the top and bottom of the list
> respectively; so I programmed that action in for you. There is only one
> downside to the code I've posted... if the user presses and leaves
> pressed the up/down arrow keys, they will be able to watch the selection
> move quickly up/down the list without highlighting individual lines
> until the arrow key is released. Other than that small visual anomaly,
> the code should do what you want.
>
> Rick - MVP
>
> Private Sub RichTextBox1_Click()
> With RichTextBox1
> .UpTo vbLf, False, False
> .Span vbCr, True, True
> End With
> ' The line the user clicked on is now highlighted; put
> ' whatever code you wanted to follow this action here
> End Sub
>
> Private Sub RichTextBox1_KeyUp(KeyCode As Integer, Shift As Integer)
> Dim HighLight As Boolean
> With RichTextBox1
> Select Case KeyCode
> Case vbKeyUp, vbKeyDown, vbKeyPageUp, vbKeyPageDown
> HighLight = True
> Case vbKeyHome
> HighLight = True
> .SelStart = 0
> Case vbKeyEnd
> HighLight = True
> .SelStart = Len(.Text)
> End Select
> If HighLight Then
> .UpTo vbLf, False, False
> .Span vbCr, True, True
> End If
> End With
> ' The line the user clicked on is now highlighted; put
> ' whatever code you wanted to follow this action here
> End Sub
>
>
>
> "Les" <vb4@prodigy.net> wrote in message
> news:upsaJK27EHA.1188@tk2msftngp13.phx.gbl...
> > Hey Rick thanks!!
> >
> > Man you made it look to easy <s>. BTW if after the selcetion is made
> can I
> > also make it so as you use the arrow keys or the pageup and page down
> and
> > home and end keys the selection of the entire line also happens??
> >
> > Happy Holidays and thx again
> >
> > "Rick Rothstein" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in message
> > news:uy$OJbx7EHA.2016@TK2MSFTNGP15.phx.gbl...
> > > > Suppose I have a Rich Text Box with 100 lines of strings. Now
> keep in
> > > mind
> > > > there is no word wrap so I can say that one complete line is all I
> > > want to
> > > > trigger an event. What complicates, atleast to me, is I need to be
> > > able to
> > > > just select the whole line by just doing a mouse click or use a
> scroll
> > > like
> > > > a listbox. Once the line is selected I want to have an event fire
> so
> > > I can
> > > > do some other things. I thought I can probabl use the Sel method
> to
> > > > highlight a line when the down mouse key is clicked but it is at
> this
> > > point
> > > > that I am not sure how to proceed. Maybe it is to late for the
> > > neurons to
> > > > be firing. Looking for an efficient way to accomplish this.
> > >
> > > Unless I'm not completely understanding what you want to do, you
> should
> > > be able to do everything in the Click event of the RichTextBox...
> > >
> > > Private Sub RichTextBox1_Click()
> > > SendKeys "{HOME}+{END}"
> > > ' The line the user clicked on is now highlighted; put
> > > ' whatever code you wanted to follow this action here
> > > End Sub
> > >
> > > Rick - MVP
> > >
> >
> >
>
- Next message: Rick Rothstein: "Re: re Rich Text Box"
- Previous message: DavidM: "VCL and Delphi?"
- In reply to: Rick Rothstein: "Re: re Rich Text Box"
- Next in thread: Rick Rothstein: "Re: re Rich Text Box"
- Reply: Rick Rothstein: "Re: re Rich Text Box"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|