Hi everybody!
I'm looking something which allow me to set the cursor at the beginning of my MaskedTextBox.
I have a mask like this : '00 00 00 00 00'
When I enter into my field, my cursor isn't at begin. '00 0|0 00 00 00' instead of '|00 00 00 00 00'
I tried this code :
But it doesn't work.
I tried the same code on MouseUp Action but I need to select the control.
If I do a MouseUp inside MaskedTextBox nothing happend, but if I do a MouseUp on the border of my MaskedTextBox, it works. Why?
What should I do in order to set my cursor in the first position?
I tried maskedTextBox1.SelectionStart = 0; but doesn't work.
Thanks
Lookoum
I'm looking something which allow me to set the cursor at the beginning of my MaskedTextBox.
I have a mask like this : '00 00 00 00 00'
When I enter into my field, my cursor isn't at begin. '00 0|0 00 00 00' instead of '|00 00 00 00 00'
I tried this code :
private
void
maskedTextBox1_Enter(
object
sender, EventArgs e)
{
if
((maskedTextBox1.Text.Trim()).Length == 0)
{
maskedTextBox1.Focus();
SendKeys.Send(
"{HOME}"
);
MessageBox.Show(maskedTextBox1.Focused.ToString());
}
}
But it doesn't work.
I tried the same code on MouseUp Action but I need to select the control.
If I do a MouseUp inside MaskedTextBox nothing happend, but if I do a MouseUp on the border of my MaskedTextBox, it works. Why?
What should I do in order to set my cursor in the first position?
I tried maskedTextBox1.SelectionStart = 0; but doesn't work.
Thanks
Lookoum
5 Answers, 1 is accepted
0

Lookoum
Top achievements
Rank 1
answered on 26 Mar 2012, 03:21 PM
Hi again,
I found something in order to fix my problem.
I think it's not the best way but it works.
My cursor has the right position but only when I start writing in my control.
How can I have the right position when my MaskedTextBox got the focus?
Thanks
Lookoum
I found something in order to fix my problem.
I think it's not the best way but it works.
private
void
mskTelephone_KeyPress(
object
sender, KeyPressEventArgs e)
{
if
((mskTelephone.Text.Trim()).Length == 0)
{
mskTelephone.Focus();
SendKeys.Send(
"{HOME}"
);
mskTelephone.Text = e.KeyChar.ToString();
}
}
private
void
mskTelephone_KeyUp(
object
sender, KeyEventArgs e)
{
if
((mskTelephone.Text.Trim()).Length == 1)
{
mskTelephone.SelectionStart = 1;
}
}
My cursor has the right position but only when I start writing in my control.
How can I have the right position when my MaskedTextBox got the focus?
Thanks
Lookoum
0
Accepted
Hi Lookoum,
Peter
the Telerik team
Thank you for this question.
You should handle TextBoxItem MouseUp event and RadMaskedEditBox Enter event and set the RadMaskEditBox SelectionStart property to 0.
Please refer to the attached project.
I hope this helps.
Peter
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0

Lookoum
Top achievements
Rank 1
answered on 29 Mar 2012, 09:02 AM
Hi Peter,
Thanks a lot!
I was looking for the TextBoxElement in the MaskedTextBox in order to catch the mouse_up event but didn't find it.
this.mskTelephone.MaskedEditBoxElement.TextBoxItem.MouseUp += new MouseEventHandler(TextBoxItem_MouseUp);
Have a nice day!
Best regards
Lookoum
Thanks a lot!
I was looking for the TextBoxElement in the MaskedTextBox in order to catch the mouse_up event but didn't find it.
this.mskTelephone.MaskedEditBoxElement.TextBoxItem.MouseUp += new MouseEventHandler(TextBoxItem_MouseUp);
Have a nice day!
Best regards
Lookoum
0

Dante
Top achievements
Rank 1
answered on 21 Jun 2017, 02:27 PM
Hi Peter,
I have the same problem but I'n not using Visual Studio I'm using only Telereik Test studio in a test with a WPF aplication, I tried with your solution and the solution of lookoum usig a step code and it doesn't work, If you could help me I would thank you.
Greetings.
0
Hello Dante,
Thank you for writing.
I would like to note that this forum is related to the Telerik UI for WinForms suite. However, it seems that your question is related to WPF. Feel free to post in the relevant forum: http://www.telerik.com/forums
Thank you for your understanding.
Regards,
Dess
Progress Telerik
Thank you for writing.
I would like to note that this forum is related to the Telerik UI for WinForms suite. However, it seems that your question is related to WPF. Feel free to post in the relevant forum: http://www.telerik.com/forums
Thank you for your understanding.
Regards,
Dess
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.