Scroll Bar Position control
-
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
-
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
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 instanceMyEdit.LineScroll(MyEdit.GetFirstVisibleLine(), 0)
makes the top line of the text in the edit control visible
Graham Librarians rule, Ook!
-
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 instanceMyEdit.LineScroll(MyEdit.GetFirstVisibleLine(), 0)
makes the top line of the text in the edit control visible
Graham Librarians rule, Ook!
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
-
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
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 usingGetLineFromCharIndex
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 theGetFirstCharIndexFromLine
f) Set the caret to begining of the line calculated above using theSelect
method g) Scroll the caret to the bottom of the display using theScrollToCaret()
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 workingGraham Librarians rule, Ook!