Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. RTB Redraw problem

RTB Redraw problem

Scheduled Pinned Locked Moved C#
helpquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    IceWater42
    wrote on last edited by
    #1

    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 ??? }

    M A 2 Replies Last reply
    0
    • I IceWater42

      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 ??? }

      M Offline
      M Offline
      MoustafaS
      wrote on last edited by
      #2

      Have you tried Refresh and Update methods ??, the Update method should do it.


      About : Islam
      About : Me

      I 1 Reply Last reply
      0
      • I IceWater42

        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 ??? }

        A Offline
        A Offline
        Abisodun
        wrote on last edited by
        #3

        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 1 Reply Last reply
        0
        • M MoustafaS

          Have you tried Refresh and Update methods ??, the Update method should do it.


          About : Islam
          About : Me

          I Offline
          I Offline
          IceWater42
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • A Abisodun

            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 Offline
            I Offline
            IceWater42
            wrote on last edited by
            #5

            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!

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups