Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / May 2008

Tip: Looking for answers? Try searching our database.

How to control size of length in richtexbox per line ?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Eng Teng - 12 May 2008 13:48 GMT
How to control size of length in richtexbox per line ?

Regards,
Tee
David Glienna - 14 May 2008 02:30 GMT
Option Explicit

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As
String) As Long

Private Const EM_GETLINE = &HC4
Private Const EM_LINELENGTH = &HC1

Private Function ColorWords(ByRef rtb As RichTextBox, _
                           ByRef sFindString As String, _
                           ByVal lColor As Long) As Integer
On Error GoTo ErrHandler
   Dim lFindLength         As Long
   Dim lFoundPos           As Long
   Dim lTempPos            As Long
   Dim iOptions            As Integer
   Dim iMatchCount         As Integer

   ' Set search options
   iOptions = rtfNoHighlight 'used by default here
   If Check1(0).Value = 1 Then iOptions = iOptions + rtfWholeWord
   If Check1(1).Value = 1 Then iOptions = iOptions + rtfMatchCase

   ' Save the string-length
   lFindLength = Len(sFindString)

   ' Search for a single match. Find method returns
   ' the position of the first character of the item,
   ' or -1 if no matches are found.
   lFoundPos = rtb.Find(sFindString, 0, , iOptions)

   ' Loop until all occurences are found
   Do Until lFoundPos < 0
       iMatchCount = iMatchCount + 1
       rtb.SelStart = lFoundPos
       rtb.SelLength = lFindLength
       rtb.SelColor = lColor
       lTempPos = lFoundPos + lFindLength
       lFoundPos = rtb.Find(sFindString, lTempPos, , iOptions)
   Loop

   ' Return the number of matches
   ColorWords = iMatchCount
   Exit Function

ErrHandler:
   MsgBox "Unexpected error number-" & _
       CStr(Err.Number) & _
       " occurred in " & Err.Source & _
       ":" & vbCrLf & vbCrLf & Err.Description
End Function

Private Sub Command1_Click()
  ColorWords RichTextBox1, txtSearch.Text, vbRed
End Sub

Private Sub RichTextBox1_Click()

   Dim strBuffer As String
   Dim lngLength As Long
   Dim intCurrentLine As Integer
   Dim lngLineNumber As Long
       With RichTextBox1
       intCurrentLine = .GetLineFromChar(.SelStart)
       'get line length
       lngLength = SendMessage(.hwnd, EM_LINELENGTH, intCurrentLine, 0)
       'resize buffer
       strBuffer = Space(lngLength)
       'get line text
       Call SendMessage(.hwnd, EM_GETLINE, intCurrentLine, ByVal strBuffer)

       lngLineNumber = .GetLineFromChar(.SelStart)
       MsgBox "You selected line number " & lngLineNumber + 1 & " which
says " & strBuffer
   End With
End Sub

Signature

David Glienna
MVP - Visual Developer (Visual Basic)
2006 thru 2008

> How to control size of length in richtexbox per line ?
>
> Regards,
> Tee

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.