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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rich Text Box Line Select and Delete 1

Status
Not open for further replies.

BBousman

Programmer
May 10, 2004
57
US
I have a rich text box on my form. What I want to do is make it so no matter where you're at on the line it will delete that entire line depending on where the cursor is. I've messed around with the selStart, selLength properties of the rich text box but to no avail. Anyone got any ideas?

Example:
The patient is in today for followup. Still having significant pain, localizes to the left buttock. Patient still not back to her normal activities. Patient also complaining of some left groin pain. She had had injections at L1-2 to address this.

If the cursor was before the word ACTIVITIES on the second line, it would go back and go in front of the word HER and delete all the way to ADDRESS.

~Brett
 
JohnYingling~

I can't exactly look for the vbCrLf because the right margin of the rich text box won't always be a carriage return or line feed. The text has the ability to run onto multiple lines without hitting the 'Enter' key.

~Brett
 
Here's an illustration of one technique. You'll need a form with a rich textbox set to multiline with some text in it:
Code:
[COLOR=blue]
Option Explicit

Private Const EM_LINELENGTH = &HC1
Private Const EM_LINEINDEX = &HBB

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 ' generic declaration

Private Sub RichTextBox1_Click()
    Dim StartChar As Long
    Dim LineLen As Long
    StartChar = SendMessage(RichTextBox1.hwnd, EM_LINEINDEX, -1&, 0&)
    LineLen = SendMessage(RichTextBox1.hwnd, EM_LINELENGTH, StartChar, 0&)
    
    RichTextBox1.SelStart = StartChar
    RichTextBox1.SelLength = LineLen
    RichTextBox1.SelText = ""
End Sub
[/color]
 
strongm~
Thanks!! That worked for the most part! I had to adjust it a little to fit my code how I wanted it but it did what I need it to! Thanks!!

~Brett
 
strongm~
Actually there's one little problem with it....I can get it to delete the line but it also deletes the first word on the next line?!?!?!

Ex:
The patient is in today for followup. Reports that he is doing quite well. He was in a motor vehicle accident on Monday.

The code will delete the first sentence as well as the word Monday

Any ideas of how to stop it from doing that?

~Brett
 
I don't know just how you have recoded it to work in your project, so I can't advise. Suffice it to say that the original code, as given here, does not suffer the problem you are describing (at least, not on my PC)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top