Click here to Skip to main content
15,513,143 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 3:32
mvaPete O'Hanlon4-Jul-18 3:32 
QuestionMaskedTextBox Focus ? Pin
ibrahimayhans3-Jul-18 2:42
ibrahimayhans3-Jul-18 2:42 
AnswerRe: MaskedTextBox Focus ? Pin
OriginalGriff3-Jul-18 3:19
mveOriginalGriff3-Jul-18 3:19 
GeneralRe: MaskedTextBox Focus ? Pin
ibrahimayhans3-Jul-18 3:33
ibrahimayhans3-Jul-18 3:33 
AnswerRe: MaskedTextBox Focus ? Pin
Eddy Vluggen3-Jul-18 3:31
professionalEddy Vluggen3-Jul-18 3:31 
GeneralRe: MaskedTextBox Focus ? Pin
ibrahimayhans3-Jul-18 3:34
ibrahimayhans3-Jul-18 3:34 
GeneralRe: MaskedTextBox Focus ? Pin
Eddy Vluggen3-Jul-18 3:37
professionalEddy Vluggen3-Jul-18 3:37 
AnswerRe: MaskedTextBox Focus ? Pin
Alan N3-Jul-18 4:29
Alan N3-Jul-18 4: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 19:44
Member 128234452-Jul-18 19:44 
AnswerRe: Following Jose Menendez Póo Calendar project Pin
Peter_in_27802-Jul-18 20:34
professionalPeter_in_27802-Jul-18 20:34 
AnswerRe: Following Jose Menendez Póo Calendar project Pin
OriginalGriff2-Jul-18 21:51
mveOriginalGriff2-Jul-18 21:51 
AnswerRe: Following Jose Menendez Póo Calendar project Pin
Eddy Vluggen3-Jul-18 0:21
professionalEddy Vluggen3-Jul-18 0:21 
QuestionIt must parse string numbers to integer but it's out is zero Pin
Member 138946071-Jul-18 21:49
Member 138946071-Jul-18 21:49 
AnswerRe: It must parse string numbers to integer but it's out is zero Pin
Richard MacCutchan1-Jul-18 22:37
mveRichard MacCutchan1-Jul-18 22:37 
AnswerRe: It must parse string numbers to integer but it's out is zero Pin
OriginalGriff1-Jul-18 22:39
mveOriginalGriff1-Jul-18 22:39 
Questionc# Pin
Member 1389187630-Jun-18 8:18
Member 1389187630-Jun-18 8:18 
AnswerRe: c# Pin
Pete O'Hanlon30-Jun-18 9:03
mvaPete O'Hanlon30-Jun-18 9:03 
AnswerRe: c# Pin
Dave Kreskowiak30-Jun-18 15:26
mveDave Kreskowiak30-Jun-18 15:26 
AnswerRe: c# Pin
#realJSOP2-Jul-18 2:04
mva#realJSOP2-Jul-18 2:04 
GeneralRe: c# Pin
Richard Deeming2-Jul-18 8:59
mveRichard Deeming2-Jul-18 8:59 
GeneralRe: c# Pin
Nathan Minier2-Jul-18 9:20
professionalNathan Minier2-Jul-18 9:20 
GeneralRe: c# Pin
#realJSOP2-Jul-18 9:30
mva#realJSOP2-Jul-18 9:30 
GeneralRe: c# Pin
Richard Deeming2-Jul-18 9:33
mveRichard Deeming2-Jul-18 9:33 
Question{ get; set; } Pin
Xarzu29-Jun-18 10:17
Xarzu29-Jun-18 10:17 
AnswerRe: { get; set; } Pin
harold aptroot29-Jun-18 10:37
harold aptroot29-Jun-18 10: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.