RTB Redraw problem
-
I have updated my RichTextBox but i can't get it to redraw. I have tried several ways but the only one that somewhat works is to SELECT the data that is being updated .. but that has the nauseating effect on the User of causing the entire RTB text to scroll ... bad bad bad. (no human input is involved in updating the RTB ... 183 lines are updated in microseconds ... unless SELECT is used ... then it takes a second or so) The RTB gets updated just great, but i can not get it to redraw. Suggestions, please. private void UpdateRemainingTimes() { for (int n = 0; n < numReminders; n++) { string remainingTimeStr = GetRemainingTimeString(remDate[n]); int lineIndex = ReminderRTB.GetFirstCharIndexFromLine(n); int indexToDDD = lineIndex + 16; ReminderRTB.Text.Remove(indexToDDD,remainingTimeStr.Length); // delete old stuff ReminderRTB.Text.Insert(indexToDDD, remainingTimeStr); // put in new stuff } ReminderRTB.Invalidate(); // ??? does not cause the control to be redrawn ??? }
-
I have updated my RichTextBox but i can't get it to redraw. I have tried several ways but the only one that somewhat works is to SELECT the data that is being updated .. but that has the nauseating effect on the User of causing the entire RTB text to scroll ... bad bad bad. (no human input is involved in updating the RTB ... 183 lines are updated in microseconds ... unless SELECT is used ... then it takes a second or so) The RTB gets updated just great, but i can not get it to redraw. Suggestions, please. private void UpdateRemainingTimes() { for (int n = 0; n < numReminders; n++) { string remainingTimeStr = GetRemainingTimeString(remDate[n]); int lineIndex = ReminderRTB.GetFirstCharIndexFromLine(n); int indexToDDD = lineIndex + 16; ReminderRTB.Text.Remove(indexToDDD,remainingTimeStr.Length); // delete old stuff ReminderRTB.Text.Insert(indexToDDD, remainingTimeStr); // put in new stuff } ReminderRTB.Invalidate(); // ??? does not cause the control to be redrawn ??? }
Have you tried
Refresh
andUpdate
methods ??, theUpdate
method should do it.
-
I have updated my RichTextBox but i can't get it to redraw. I have tried several ways but the only one that somewhat works is to SELECT the data that is being updated .. but that has the nauseating effect on the User of causing the entire RTB text to scroll ... bad bad bad. (no human input is involved in updating the RTB ... 183 lines are updated in microseconds ... unless SELECT is used ... then it takes a second or so) The RTB gets updated just great, but i can not get it to redraw. Suggestions, please. private void UpdateRemainingTimes() { for (int n = 0; n < numReminders; n++) { string remainingTimeStr = GetRemainingTimeString(remDate[n]); int lineIndex = ReminderRTB.GetFirstCharIndexFromLine(n); int indexToDDD = lineIndex + 16; ReminderRTB.Text.Remove(indexToDDD,remainingTimeStr.Length); // delete old stuff ReminderRTB.Text.Insert(indexToDDD, remainingTimeStr); // put in new stuff } ReminderRTB.Invalidate(); // ??? does not cause the control to be redrawn ??? }
I don't recall where I found this but it should solve both of you problems: Private Const WM_SETREDRAW As Integer = &HB Private Const WM_USER As Integer = &H400 Private Const EM_GETEVENTMASK As Integer = (WM_USER + 59) Private Const EM_SETEVENTMASK As Integer = (WM_USER + 69) Private Declare Auto Function SendMessage Lib "user32.dll" ( _ ByVal hWnd As IntPtr, _ ByVal msg As Integer, _ ByVal wParam As Integer, _ ByVal lParam As IntPtr) As IntPtr ' We want to suspend redrawing because we need to select each ' character in turn to determine its fonts. However, RichTextBox ' appears to be missing some properties to do this, so use API: ' Stops RichText redrawing: richTextBox1.SuspendLayout() SendMessage(richTextBox1.Handle, WM_SETREDRAW, 0, IntPtr.Zero) ' Stops RichText sending any events: Dim eventMask As IntPtr = SendMessage( _ richTextBox1.Handle, EM_GETEVENTMASK, 0, IntPtr.Zero) ' Get the selection extent: Dim selStart = richTextBox1.SelectionStart Dim selEnd = richTextBox1.SelectionStart + richTextBox1.SelectionLength ... perform processing here ... ' Turn events back on again: SendMessage(richTextBox1.Handle, EM_SETEVENTMASK, 0, eventMask) ' Select the correct range (we must do this with events on otherwise ' the scroll state is inconsistent): richTextBox1.Select(selStart, selSize) ' Turn redraw back on again: SendMessage(richTextBox1.Handle, WM_SETREDRAW, 1, IntPtr.Zero) richTextBox1.ResumeLayout() ' Show changes richTextBox1.Invalidate()
-
Have you tried
Refresh
andUpdate
methods ??, theUpdate
method should do it.
yes, i tried: ReminderRTB.Invalidate(); ReminderRTB.Refresh(); ReminderRTB.Update(); in many flavors and combinations ... lol i am beginning to wonder if there might be some property i have inadvertantly set that would prevent the redraws.
-
I don't recall where I found this but it should solve both of you problems: Private Const WM_SETREDRAW As Integer = &HB Private Const WM_USER As Integer = &H400 Private Const EM_GETEVENTMASK As Integer = (WM_USER + 59) Private Const EM_SETEVENTMASK As Integer = (WM_USER + 69) Private Declare Auto Function SendMessage Lib "user32.dll" ( _ ByVal hWnd As IntPtr, _ ByVal msg As Integer, _ ByVal wParam As Integer, _ ByVal lParam As IntPtr) As IntPtr ' We want to suspend redrawing because we need to select each ' character in turn to determine its fonts. However, RichTextBox ' appears to be missing some properties to do this, so use API: ' Stops RichText redrawing: richTextBox1.SuspendLayout() SendMessage(richTextBox1.Handle, WM_SETREDRAW, 0, IntPtr.Zero) ' Stops RichText sending any events: Dim eventMask As IntPtr = SendMessage( _ richTextBox1.Handle, EM_GETEVENTMASK, 0, IntPtr.Zero) ' Get the selection extent: Dim selStart = richTextBox1.SelectionStart Dim selEnd = richTextBox1.SelectionStart + richTextBox1.SelectionLength ... perform processing here ... ' Turn events back on again: SendMessage(richTextBox1.Handle, EM_SETEVENTMASK, 0, eventMask) ' Select the correct range (we must do this with events on otherwise ' the scroll state is inconsistent): richTextBox1.Select(selStart, selSize) ' Turn redraw back on again: SendMessage(richTextBox1.Handle, WM_SETREDRAW, 1, IntPtr.Zero) richTextBox1.ResumeLayout() ' Show changes richTextBox1.Invalidate()
i am SOOOOOOO embarassed ... complete noobie mistake .. failed to assign the RTB: adding "ReminderRTB.Text = " to the front of these statements resolved the problem. <> ReminderRTB.Text.Remove(indexToDDD,remainingTimeStr.Length); // delete old stuff ReminderRTB.Text.Insert(indexToDDD, remainingTimeStr); // put in new stuff ... but thanks for trying to help!