Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
I use the masktextbox component in my application,i find a question:
when i set property as below:
C#
maskedTextBox1.Mask = "CX&&&&&&&&&&Y&&&&&&&&&&Z&&&&&&&&&&";
maskedTextBox1.PromptChar = ' ';

//int i = 0;

and i write click event as below:
C#
maskedTextBox1.Select(i++, 0);
maskedTextBox1.Focus();

it can't control the component focus.

so i change another way as below:
C#
maskedTextBox1.SelectionStart = i++;
maskedTextBox1.Focus();

it also can't control.

how can i control the maskedtextbox focus.
can anybody help me ?
Posted
Updated 15-Sep-15 19:39pm
v4
Comments
Thava Rajan 16-Sep-15 8:26am    
where did you put your selection code?
Thava Rajan 16-Sep-15 8:26am    
maskedTextBox1.Select(i++, 0);
or
maskedTextBox1.SelectionStart = i++;

try to use it in reverse order
C#
maskedTextBox1.Focus();
maskedTextBox1.Select(i++, 0);
 
Share this answer
 
Have you tried this one?
this.ActiveControl = maskedTextBox1
 
Share this answer
 
Comments
xuyunhai 16-Sep-15 4:30am    
i tried it, it not achive my purpose.
if the change the component to textbox,the click will valid。
but my require is use maskedtextbox component,so how can i solve this question?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900