Masked TextBox Input Align Left

I have a disguised text field in my winforms application where, if the user clicks inside a hidden text field, the cursor will start working in that place. For example, if they visit the middle of a hidden text field, the cursor will blink in the middle. How can I make the cursor behave such that it will default to the leftmost part of the masked text field?

+4
source share
2 answers

You can connect to 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); } 
+5
source

in the click event:

 maskedTextBoxname.SelectionStart = 0; 

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

 maskedTextBoxname.SelectionStart = maskedTextBoxname.Text.Length; 

(at the same time, when you click on maskedtextbox, the cursor will appear on the last char recorded, if maskedtextbox is empty, the cursor will appear on the left)

0
source

All Articles