Masked TextBox Input Align Left

2020-02-07 03:16发布

I have a masked textbox on my winforms application where if a user clicks inside of the masked textbox, the cursor will start out in that location. For example, if they click in the middle of the masked textbox there will be a blinking cursor in the middle. How can I get the cursor behavior to be such that it will default at the left-most portion of the masked textbox?

2条回答
迷人小祖宗
2楼-- · 2020-02-07 03:42

You can hook into the click event and then do something like this:

    public Form1()
    {
        InitializeComponent();
        this.maskedTextBox1.Click+=new EventHandler(maskedTextBox1_Click);
    }

    private void maskedTextBox1_Click(object sender, EventArgs e)
    {
        this.maskedTextBox1.Select(0, 0);
    }
查看更多
啃猪蹄的小仙女
3楼-- · 2020-02-07 03:44

into the click event :

maskedTextBoxname.SelectionStart = 0;

(with this when you click on the maskedtextbox the cursor will appear at the left)

maskedTextBoxname.SelectionStart = maskedTextBoxname.Text.Length;

(with this when you click on the maskedtextbox the cursor will appear at the last char written, if the maskedtextbox is empty the cursor will appear at the left)

查看更多
登录 后发表回答