7

Do you want to move the typing position to the end of the line if you delete the...

 3 years ago
source link: https://www.codesd.com/item/do-you-want-to-move-the-typing-position-to-the-end-of-the-line-if-you-delete-the-last-character-and-replace-it-instantly-c.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Do you want to move the typing position to the end of the line if you delete the last character and replace it instantly C #

advertisements

I've got a textbox that resets back to 0 everytime you delete the last number in the textbox, but what makes this annoying is that when it replaces it; the cursor that you type with moves to the left of the 0, making anything you type afterwards have a 0 after it unless you click after the 0. Is it possible to make it so that when I delete the last digit, it goes back to the right of the newly replaced digit?

    private void iterations_TextChanged(object sender, EventArgs e)
    {
        resetToZero(iterations);
    }

    private void resetToZero(TextBox x)
    {
        if (x.Text == "")
        {
            x.Text = "0";
        }
    }


To put the cursor at the end of the text, you can just set the SelectionStart to 1, which is right after the 0, or more generically, you can use the length of the text box Text property:

private void resetToZero(TextBox x)
{
    if (x.Text == "")
    {
        x.Text = "0";
        x.SelectionStart = x.TextLength;;
    }
}

Or, to put the zero there and then select the text automatically, you can do do:

private void resetToZero(TextBox x)
{
    if (x.Text == "")
    {
        x.Text = "0";
        x.SelectionLength = x.TextLength;
    }
}

Tags textbox

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK