Performance problem RichtTextBox control

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello
Some years ago I wrote an application (a sequencer) in VB5 and then in VB6 which records and plays MIDI signals from and to an electronic organ. The MIDI information is displayed in a RichText box (named Data, say). While playing, the info about the particular MIDI signal being sent is coloured red (and once again black after sending) simultaneously, using the statement
Data.SelStart=<location in the string
Data.SelLength=<length of the info
Data.SelColor=<red or black
Now the program has been upgraded to VB.NET and the ActiveX RichTextBox control has been replaced by the equivalent System.Windows.Forms control. It appears that the execution time for the above three statements is about 30 to 50 times longer than in case of the AxRTBox control. Hence the info shown is lagging increasingly behind the sent data. The time lag is dependent on the number of characters in the RT Box; longer text yield longer execution times. This is not the case with AxRTBoxes; they show constant times. Hence I am back to AxRTBoxes, but that is rather disappointing as they will be phased out in due course

Anyone who knows this problem? Would it be a real bug, to be fixed by Microsoft

Thank you
Reinier
 
* "=?Utf-8?B?UmVpbmllcg==?= said:
Some years ago I wrote an application (a sequencer) in VB5 and then in
VB6 which records and plays MIDI signals from and to an electronic
organ. The MIDI information is displayed in a RichText box (named Data,
say). While playing, the info about the particular MIDI signal being
sent is coloured red (and once again black after sending)
simultaneously, using the statements
Data.SelStart=<location in the string>
Data.SelLength=<length of the info>
Data.SelColor=<red or black>
Now the program has been upgraded to VB.NET and the ActiveX
RichTextBox control has been replaced by the equivalent
System.Windows.Forms control. It appears that the execution time for the
above three statements is about 30 to 50 times longer than in case of
the AxRTBox control.

The fastest way is to manipulate the RTF code itself ('Rtf' property).
A reference for the RTF format can be found here:

Rich Text Format (RTF) Specification, version 1.6
<http://msdn.microsoft.com/library/en-us/dnrtfspec/html/rtfspec.asp>

Alternatively, you can prevent the control from updating when performing
successive changes to its contents.

My FAQ:

Disable redrawing of a control:

\\\
Private Declare Auto Function SendMessage Lib "user32.dll" ( _
ByVal hWnd As IntPtr, _
ByVal wMsg As Int32, _
ByVal wParam As Boolean, _
ByVal lParam As Int32 _
) As Int32

Private Const WM_SETREDRAW As Int32 = &HB
..
..
..
With Me.RichTextBox1
SendMessage(.Handle, WM_SETREDRAW, False, 0)

' Manipulate contents.
Dim i As Integer
For i = 0 To Len(.Text)
.SelectionStart = i
.SelectionLength = 1
.SelectionColor = Color.Red
.SelectionFont = New Font(.SelectionFont, FontStyle.Bold)
Next i
SendMessage(.Handle, WM_SETREDRAW, True, 0)
.Refresh()
End With
///
 
Thanks for your suggestions. However they seem not to help

Manipulating the RTF code itself means that the text should be restored in the RTBox after every color change. That would be very time consuming. Or don't I understand your suggestion

I prevented the code from intermediate updating using SendMessage(...), but no gain in performance; apparently the redraw does not take much time

Then I wrote two simple test programs, one with a Windows RTBox and the other with an AxRTBox. The results are as follows. When the execution time of the AxRTBox is normalized to 1.0, then the time for the WinRTBox with redraw is 1.57 and without redraw 1.56. Actually the gain in performance without redraw is very small, which means that most of the time spent is in the execution of the other statements (maybe seeking the location with SelectionStart)
Yet I have to figure out why the difference between the AxRTBox and the WinRTBox is now only a factor of 1.56, while I found 30 to 50 in my original app
By the way, the execution time for the test program in VB6 with W98SE is 0.25 and with XP is 0.41. ;
If you are interested in the test programs, let me know to which address I should email them (or how I should upload)

Reinie
 
Back
Top