none
write in current position RRS feed

  • Question

  • Hi,

    I am developing a virtual keyboard form with all keys on it and a TextBox to write the result

    I am using text_position to store the current position in order to write on it

    for example if the user wrote Jon and he wanted to add h so he will click after o then click the button O

    here is the code:

    private void txtKeyboard_Leave(object sender, EventArgs e)
    {
        text_position = txtKeyboard.SelectionStart;
    }
    
    private void btnKeyH_Click(object sender, EventArgs e)
    {
        txtKeyboard.Text = txtKeyboard.Text.Insert(text_position, ((DevExpress.XtraEditors.SimpleButton)sender).Text);
    }
    

    now the problem... I can write to the same position with out issue but after clicking btnKeyH  the cursor will remain in the same position although it should move after the newly written h letter.

    How can I solve this?

    Monday, May 27, 2013 9:46 PM

Answers

  • Move the selection:

    private void btnKeyH_Click(object sender, EventArgs e)
    {
        txtKeyboard.Text = txtKeyboard.Text.Insert(text_position, ((DevExpress.XtraEditors.SimpleButton)sender).Text);
    
        // Increment your position for next character
        ++text_position;
        // Move the cursor
        txtKeyboard.SelectionStart = text_position;
    }


    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Monday, May 27, 2013 10:55 PM
    Moderator
  • Since text_position is SelectionStart, you can remove it and try this as well:

    string text = ((DevExpress.XtraEditors.SimpleButton)sender).Text;
    txtKeyboard.SelectedText = text;
    txtKeyboard.SelectionStart += text.Length;


    Tuesday, May 28, 2013 6:01 AM

All replies

  • Move the selection:

    private void btnKeyH_Click(object sender, EventArgs e)
    {
        txtKeyboard.Text = txtKeyboard.Text.Insert(text_position, ((DevExpress.XtraEditors.SimpleButton)sender).Text);
    
        // Increment your position for next character
        ++text_position;
        // Move the cursor
        txtKeyboard.SelectionStart = text_position;
    }


    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Monday, May 27, 2013 10:55 PM
    Moderator
  • Since text_position is SelectionStart, you can remove it and try this as well:

    string text = ((DevExpress.XtraEditors.SimpleButton)sender).Text;
    txtKeyboard.SelectedText = text;
    txtKeyboard.SelectionStart += text.Length;


    Tuesday, May 28, 2013 6:01 AM
  • this is the code I use and it's working perfectly except for the AND & symbol. The AND & is typed twice when I click on the & button and the current position will be between the two & signs.

    How can I  fix it?

    private void write_key(string key_caption)
    {
        txtKeyboard.Text = txtKeyboard.Text.Insert(text_position, key_caption);
    
        // Increment your position for next character
        ++text_position;
    
        // Move the cursor
        txtKeyboard.SelectionStart = text_position;
    }
    

    private void btnKey0_Click(object sender, EventArgs e)
    {
        write_key(((DevExpress.XtraEditors.SimpleButton)sender).Text);
    }
    

    Friday, May 31, 2013 9:01 PM
  • Select the “&” button and set the UseMnemonic property to false. Then change the text from “&&” to “&”.

    Saturday, June 1, 2013 2:21 PM
  • simplebutton from DevExpress doesn't support usemnemonic?!
    Saturday, June 1, 2013 6:25 PM
  • Hi,

    What about buttons related to Keys not to letters, numbers or symbols.

    For example.. I have Backspace button and I want to invoke a backspace from the current position if the user clicked on the backspace button?

    Same with Delete button as an example.

    Monday, June 10, 2013 10:49 AM