CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 1999
    Location
    Arizona, U.S.A.
    Posts
    101

    Edit Box (Single)

    Hi,
    I have two edit boxes for the user to enter date info. (Example: 01-04-1999) I have tried the EN_MAXTEXT. Problem: EN_MAXTEXT works fine, but I want to allow my user to have the cursor placed in the next field when the last character in the date is entered. Not when an extra character is entered. Would someone be so kind as to show me how I can do this? Sample code is always welcome and steps needed to implement! Thank You Very Much!
    Charlie

    Everything is Free Until You Have to Pay for it....

    Platform is Windows 2000/XP Professional, Visual C++ 6.0

  2. #2
    Join Date
    Apr 1999
    Location
    California USA
    Posts
    15

    Re: Edit Box (Single)

    First, you need to create EN_CHANGE message handler for the first editbox.
    Second, do validation in the function everytime the user typing a character in the editbox.
    Third, once the user enters a valid data info or reaches the MAXLENGTH of editbox, you set the focus to the second editbox.

    For example: two editboxes m_edit1 and m_edit2 (CEdit objects).
    // EN_CHANGE message handler for m_edit1
    void CMyXXXXX::OnChangeEdit1()
    {
    // TODO: If this is a RICHEDIT control, the control will not
    // send this notification unless you override the CDialog::OnInitDialog()
    // function to send the EM_SETEVENTMASK message to the control
    // with the ENM_CHANGE flag ORed into the lParam mask.

    // TODO: Add your control notification handler code here
    CString text=_T("");
    m_edit1.GetWindowText(text); // get current typed text from editbox 1

    if (text.GetLength() >= MAX_DATALENGTH ||
    ValidateData(text) == TRUE){
    m_edit2.SetFocus();
    }
    }

    Note: the MAX_DATELENGTH is the max characters allowed in edit1.
    the ValidateData() is a function you validate the data info.

    Hope this will help. Good luck.

    Allen


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured