05-07-2010 04:59 PM
I have a text box to receive user commands and display them. Each line of the text box starts with a prompt character (like a DOS window). Here is a snippet of the code that gets the command and displays a prompt for the next command:
status = GetTextBoxLine (PANEL, PANEL_TEXTBOX, lineNumber, currentCmd);
status = InsertTextBoxLine (PANEL, PANEL_TEXTBOX, -1, ">\n");
The problem I am having is that I want the cursor to automatically go to the last line of the display, but it always stays at the top line. If I add the following code per another thread in this forum, the cursor moves to the correct line, but is in front of the prompt character:
SetActiveCtrl (PANEL, PANEL_TEXTBOX);
FakeKeystroke (VAL_RIGHT_ARROW_VKEY);
The user could move the cursor to the correct location in either of these instances, but that seems like a clunky way of doing things. Is there a way I can get the cursor to be positioned at the last line of the box programmatically?
Thanks.
05-08-2010 03:02 AM
Did you consider using SetCtrlAttribute (PANEL, PANEL_TEXTBOX, ATTR_TEXT_SELECTION_START, position)? All you have to do is keeping track of your text box contents, i.e. its length.
Wolfgang
05-09-2010 04:41 PM - edited 05-09-2010 04:42 PM
Wolfgang wrote:Did you consider using SetCtrlAttribute (PANEL, PANEL_TEXTBOX, ATTR_TEXT_SELECTION_START, position)? All you have to do is keeping track of your text box contents, i.e. its length.
Wolfgang
Alternatively you can use GetCtrlAttribute (panelHandle, PANEL_TEXTBOX, ATTR_STRING_TEXT_LENGTH, &x); to obtain the lenght in characters of the text in the textbox without need to trace textbox usage.
05-10-2010 03:11 AM
Alternatively just use SetCtrlVal (panelHandle, PANEL_TEXTBOX, line_to_add). This will automatically keep the cursor on the last line of the box, if the line_to_add string has a '\n' at the end of it.
JR
05-10-2010 11:26 AM
Gentlemen,
Thanks for your suggestions. They helped me to achieve the result I was looking for.