Click here to Skip to main content
15,884,700 members
Home / Discussions / C#
   

C#

 
AnswerRe: Filter records between two dates( using two datepicker) from text file in c# Pin
Pete O'Hanlon4-Jul-18 2:32
mvePete O'Hanlon4-Jul-18 2:32 
QuestionMaskedTextBox Focus ? Pin
ibrahimayhans3-Jul-18 1:42
ibrahimayhans3-Jul-18 1:42 
AnswerRe: MaskedTextBox Focus ? Pin
OriginalGriff3-Jul-18 2:19
mveOriginalGriff3-Jul-18 2:19 
GeneralRe: MaskedTextBox Focus ? Pin
ibrahimayhans3-Jul-18 2:33
ibrahimayhans3-Jul-18 2:33 
AnswerRe: MaskedTextBox Focus ? Pin
Eddy Vluggen3-Jul-18 2:31
professionalEddy Vluggen3-Jul-18 2:31 
GeneralRe: MaskedTextBox Focus ? Pin
ibrahimayhans3-Jul-18 2:34
ibrahimayhans3-Jul-18 2:34 
GeneralRe: MaskedTextBox Focus ? Pin
Eddy Vluggen3-Jul-18 2:37
professionalEddy Vluggen3-Jul-18 2:37 
AnswerRe: MaskedTextBox Focus ? Pin
Alan N3-Jul-18 3:29
Alan N3-Jul-18 3:29 
I think you are asking how to move the textbox caret to position 0 when the empty textbox is clicked.

The first part is to get the empty state of the maskedtextbox before any data has been entered. At that point the Text property value is not String.Empty but a representation of the mask. This 'empty' text can be obtained by capturing the Text when the MaskChanged event fires. For your example it is
"(   )        "

The second part is picking a suitable place to move the caret. When an unfocussed textbox is clicked the sequence of Enter, GotFocus and Click events occur. You'll find that attempting to set the caret position in either the Enter or GotFocus events will fail and changes must be made in the Click event handler.

Combining that information gives some prototype code
C#
private String emptyText;

private void MaskedTextBox_MaskChanged(object sender, EventArgs e) {
  // Capture the empty text
  MaskedTextBox mtbx = (MaskedTextBox)sender;
  emptyText = mtbx.Text;
}

private void MaskedTextBox_Click(object sender, EventArgs e) {
  MaskedTextBox mtbx = (MaskedTextBox)sender;
  String currentText = mtbx.Text;
  if (currentText == emptyText) {
    // Move the caret to the start of the line
    mtbx.Select(0, 0);
  }
}


EDIT : Correct operation of this code requires that the MaskChanged event handler is attached before the Mask is set.
Alan.
QuestionFollowing Jose Menendez Póo Calendar project Pin
Member 128234452-Jul-18 18:44
Member 128234452-Jul-18 18:44 
AnswerRe: Following Jose Menendez Póo Calendar project Pin
Peter_in_27802-Jul-18 19:34
professionalPeter_in_27802-Jul-18 19:34 
AnswerRe: Following Jose Menendez Póo Calendar project Pin
OriginalGriff2-Jul-18 20:51
mveOriginalGriff2-Jul-18 20:51 
AnswerRe: Following Jose Menendez Póo Calendar project Pin
Eddy Vluggen2-Jul-18 23:21
professionalEddy Vluggen2-Jul-18 23:21 
QuestionIt must parse string numbers to integer but it's out is zero Pin
Member 138946071-Jul-18 20:49
Member 138946071-Jul-18 20:49 
AnswerRe: It must parse string numbers to integer but it's out is zero Pin
Richard MacCutchan1-Jul-18 21:37
mveRichard MacCutchan1-Jul-18 21:37 
AnswerRe: It must parse string numbers to integer but it's out is zero Pin
OriginalGriff1-Jul-18 21:39
mveOriginalGriff1-Jul-18 21:39 
Questionc# Pin
Member 1389187630-Jun-18 7:18
Member 1389187630-Jun-18 7:18 
AnswerRe: c# Pin
Pete O'Hanlon30-Jun-18 8:03
mvePete O'Hanlon30-Jun-18 8:03 
AnswerRe: c# Pin
Dave Kreskowiak30-Jun-18 14:26
mveDave Kreskowiak30-Jun-18 14:26 
AnswerRe: c# Pin
#realJSOP2-Jul-18 1:04
mve#realJSOP2-Jul-18 1:04 
GeneralRe: c# Pin
Richard Deeming2-Jul-18 7:59
mveRichard Deeming2-Jul-18 7:59 
GeneralRe: c# Pin
Nathan Minier2-Jul-18 8:20
professionalNathan Minier2-Jul-18 8:20 
GeneralRe: c# Pin
#realJSOP2-Jul-18 8:30
mve#realJSOP2-Jul-18 8:30 
GeneralRe: c# Pin
Richard Deeming2-Jul-18 8:33
mveRichard Deeming2-Jul-18 8:33 
Question{ get; set; } Pin
Xarzu29-Jun-18 9:17
Xarzu29-Jun-18 9:17 
AnswerRe: { get; set; } Pin
harold aptroot29-Jun-18 9:37
harold aptroot29-Jun-18 9:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.