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 / C++ / MFC
  4. Scroll Bar Position control

Scroll Bar Position control

Scheduled Pinned Locked Moved C / C++ / MFC
question
4 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.
  • U Offline
    U Offline
    User 4648425
    wrote on last edited by
    #1

    Hi Actually i have Rich text contol present in my dialog. I will get messages from the board, when the messages exceeds the size of the window, scroll bar automatically comes because of i had set the scroll bar(Vertical scroll bar) property of Rich Text Control. My question is, when message exceeds the window size, the scroll bar automatically goes up. i don want scroll bar to move up rather it should go down, then only i can able to see latest updates form the board at time itself. Thanks in advance, Thanks, Balaji

    G 1 Reply Last reply
    0
    • U User 4648425

      Hi Actually i have Rich text contol present in my dialog. I will get messages from the board, when the messages exceeds the size of the window, scroll bar automatically comes because of i had set the scroll bar(Vertical scroll bar) property of Rich Text Control. My question is, when message exceeds the window size, the scroll bar automatically goes up. i don want scroll bar to move up rather it should go down, then only i can able to see latest updates form the board at time itself. Thanks in advance, Thanks, Balaji

      G Offline
      G Offline
      Graham Shanks
      wrote on last edited by
      #2

      Not sure that I understand. When you say "get messages from the board" do you mean the keyboard? I also don't understand how adding text to a rich edit control moves the scroll bar up. If you add text to the end of the edit control then the scroll bar moves down for me. The text does move up. Perhaps you can try LineScroll() with a negative number of lines. For instance

      MyEdit.LineScroll(MyEdit.GetFirstVisibleLine(), 0)

      makes the top line of the text in the edit control visible

      Graham Librarians rule, Ook!

      R 1 Reply Last reply
      0
      • G Graham Shanks

        Not sure that I understand. When you say "get messages from the board" do you mean the keyboard? I also don't understand how adding text to a rich edit control moves the scroll bar up. If you add text to the end of the edit control then the scroll bar moves down for me. The text does move up. Perhaps you can try LineScroll() with a negative number of lines. For instance

        MyEdit.LineScroll(MyEdit.GetFirstVisibleLine(), 0)

        makes the top line of the text in the edit control visible

        Graham Librarians rule, Ook!

        R Offline
        R Offline
        ramnathrn
        wrote on last edited by
        #3

        Hi Graham, thanks for ur reply. I'm explaining the problem on behalf of Balaji. Problem : Information in Rich Text Box are updated by thread, whenever thread gets message(text), it will be updated on RichTextBox Control. Right now, we are concatenaing the message(text) and update the concate_string in the RichTextControl, using the following API, myRichTextBox.SetText(concat_string); What we are suppose to do is, recently updated text should be visible to user. To view the recent text, we are using scroll bars manually. Instead, we want to display the last updated text. we are using Rich Text Box 6.0 (SP4). we tried with the following APIs, myEdit.SetScrollBar(); but it's throwing Error.. Thanks Ram

        G 1 Reply Last reply
        0
        • R ramnathrn

          Hi Graham, thanks for ur reply. I'm explaining the problem on behalf of Balaji. Problem : Information in Rich Text Box are updated by thread, whenever thread gets message(text), it will be updated on RichTextBox Control. Right now, we are concatenaing the message(text) and update the concate_string in the RichTextControl, using the following API, myRichTextBox.SetText(concat_string); What we are suppose to do is, recently updated text should be visible to user. To view the recent text, we are using scroll bars manually. Instead, we want to display the last updated text. we are using Rich Text Box 6.0 (SP4). we tried with the following APIs, myEdit.SetScrollBar(); but it's throwing Error.. Thanks Ram

          G Offline
          G Offline
          Graham Shanks
          wrote on last edited by
          #4

          OK, things are a lot clearer now, thanks. I was assuming that you were using the CRichEditCtrl from MFC, but you are actually using RichTextBox from the .Net framework library What I think you want to do is: a) Before appending the message to the RichTextBox get the current length of the text from the TextLength property. This is the char index of the last character of the last message b) Calculate the line number of this position using GetLineFromCharIndex c) Append the text d) Calculate the line number that you want at the bottom of the display from the number calculated in b) plus the number of lines in the display e) Calculate the char index of the beginning of the line calculated in d) using the GetFirstCharIndexFromLine f) Set the caret to begining of the line calculated above using the Select method g) Scroll the caret to the bottom of the display using the ScrollToCaret() method The following code should do it (note I have not tested this yet)

          int line = myRichTextBox.GetLineFromCharIndex(myRichTextBox.TextLength);
          myRichTextBox.SetText(concat_string);
          int pos = myRichTextBox.GetFirstCharIndexFromLine(line + NumberOfLinesInRichTextBox(myRichTextBox));
          myRichTextBox.Select(pos, pos);
          myRichTextBox.ScrollToCaret();

          As in a previous answer[^] the function NumberOfLinesInRichTextBox could either return a constant value determined by experiment or calculate the number of visible lines in the RichTextBox using Text Metrics. Apologies for not having time at the moment to test this out, but I hope I've given you enough of a steer to allow you to get this working

          Graham Librarians rule, Ook!

          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