I suggest you read the very first post in the thread you linked. It says everything you would need to know to get a single composite frame out of the program.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Private Declare Auto Function SendMessage Lib "user32.dll" ( _
ByVal hWnd As IntPtr, _
ByVal wMsg As Int32, _
ByVal wParam As IntPtr, _
ByVal lParam As IntPtr _
) As IntPtr
Private Const WM_SETREDRAW As Int32 = &HB
Dim lastUsedStartIndex = 0
Dim lastUsedEndIndex = 0
Dim previousText As System.IO.StringReader = New System.IO.StringReader("")
Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged
Dim richTextBoxBufferObject As RichTextBox = CType(sender, RichTextBox)' Pass the control by reference (for use in copying
Dim previousOffset = richTextBoxBufferObject.SelectionStart ' Get current offset for use with reseting text at very end.
Dim displayedStartIndex = richTextBoxBufferObject.GetCharIndexFromPosition(New Point(richTextBoxBufferObject.Location.X, richTextBoxBufferObject.Location.Y+1)) ' Get character index at location in form.
Dim displayedEndIndex = richTextBoxBufferObject.GetCharIndexFromPosition(New Point(richTextBoxBufferObject.DisplayRectangle.Right, richTextBoxBufferObject.DisplayRectangle.Bottom-1)) ' Get character index at bottom right of RichTextBox.
Dim lineReader As System.IO.StringReader = New System.IO.StringReader(richTextBoxBufferObject.Text) ' Prepare string reader for all text in RichTextBox
Dim buffer(displayedStartIndex) As Char ' Prepare dummy object for use in following two methods.
lineReader.ReadBlock(buffer, 0, displayedStartIndex) ' Skip forward to first displayed text.
previousText.ReadBlock(buffer, 0, displayedStartIndex) ' Skip forward to first dispalyed text (in the previous buffer).
' Lock control by not sending it any events.
With Me.RichTextBox1
SendMessage( _
.Handle, WM_SETREDRAW, New IntPtr(CInt(False)), IntPtr.Zero _
)
' Do highlighting.
Dim runningLength = displayedStartIndex
Dim line As String = ""
Dim previousLine As String = ""
Dim lineCount = 0
Do While (True)
line = lineReader.ReadLine()
previousLine = previousText.ReadLine()
lineCount += 1
If (line Is Nothing) Then
Exit Do
End If
' If this line isn't the same as what we had stored before, format it.
' If this line starts earlier than the previously used start index, format it.
' If this line starts after the previously used end index, format it.
If line <> previousLine OrElse runningLength < lastUsedStartIndex OrElse runningLength > lastUsedEndIndex
' Otherwise, clear line to black.
Dim currentOffset = runningLength
richTextBoxBufferObject.Select(runningLength, line.Length)
richTextBoxBufferObject.SelectionColor = Color.Black
' Update line to green.
If line.IndexOf("//") <> -1 Then
Dim offsetOfComment = richTextBoxBufferObject.Find(str:="//", start:=runningLength, [end]:=runningLength + line.Length, options:=RichTextBoxFinds.None)
If offsetOfComment > -1 Then
currentOffset = runningLength
richTextBoxBufferObject.Select(offsetOfComment, (runningLength + line.Length - offsetOfComment))
richTextBoxBufferObject.SelectionColor = Color.Green
End If
End If
End If
' Increase running length.
runningLength += line.Length + 1
If runningLength >= displayedEndIndex
Exit Do
End If
Loop
lastUsedStartIndex = displayedStartIndex
lastUsedEndIndex = displayedEndIndex
previousText = New System.IO.StringReader(RichTextBox1.Text)
RichTextBox1.Select(previousOffset, 0)
' Unlock control by sending it events again.
SendMessage( _
.Handle, WM_SETREDRAW, New IntPtr(CInt(True)), IntPtr.Zero _
)
.Refresh()
End With
End Sub
Private Sub RichTextBox1_KeyUp( ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles RichTextBox1.KeyUp
If e.KeyCode = Keys.Down OrElse
e.KeyCode = Keys.Up OrElse
(e.KeyCode = Keys.Home Or Keys.ControlKey) OrElse
(e.KeyCode = Keys.End Or Keys.ControlKey) OrElse
e.KeyCode = Keys.PageDown OrElse
e.KeyCode = Keys.PageUp
' Get existing display for comparsion.
Dim displayedStartIndex = RichTextBox1.GetCharIndexFromPosition(New Point(RichTextBox1.Location.X, RichTextBox1.Location.Y+1))
Dim displayedEndIndex = RichTextBox1.GetCharIndexFromPosition(New Point(RichTextBox1.DisplayRectangle.Right, RichTextBox1.DisplayRectangle.Bottom-1))
' Compare to state prior to key event.
If displayedStartIndex <> lastUsedStartIndex OrElse displayedEndIndex <> lastUsedEndIndex
RichTextBox1_TextChanged(RichTextBox1, Nothing)
End If
End If
End Sub
Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged
' Reset color to black.
Dim previousOffset = RichTextBox1.SelectionStart ' Get current offset for use with reseting text.
RichTextBox1.SelectAll() ' Push all text into selection.
RichTextBox1.SelectionColor = Color.Black ' Turn to black.
RichTextBox1.SelectionStart = previousOffset ' Return selection offset to where it was.
RichTextBox1.Select(previousOffset, 0) ' Select no characters.
' Do highlighting.
Dim runningLength = 0
Dim lineCount = 0 ' Account for newlines.
For Each line In RichTextBox1.Lines
If line.Contains("//") Then
Dim offsetOfComment = RichTextBox1.Find(characterSet:="//", start:=runningLength)
Dim currentOffset = RichTextBox1.SelectionStart
RichTextBox1.SelectionStart = offsetOfComment
RichTextBox1.Select(offsetOfComment, runningLength + line.Count - offsetOfComment + lineCount)
RichTextBox1.SelectionColor = Color.Green
RichTextBox1.SelectionStart = currentOffset
RichTextBox1.Select(currentOffset, 0)
End If
lineCount = lineCount + 1
runningLength = runningLength + line.Count
Next
End Sub
Dim currentOffset = RichTextBox1.SelectionStart
RichTextBox1.SelectedText = TextBox1.Text
RichTextBox1.Focus()
RichTextBox1.SelectionStart = currentOffset
Page created in 0.021 seconds with 22 queries.