|
Prev: Remove title bar, but system menu still work
Next: How to move focus / active control using Enter key?
From: Landon on 13 May 2008 04:00 I have a form with 3 CEdit which are Year, Month and Day fields. If one of them is empty and user click OK or press Enter, an error message will displayed and the focus will back on where it was. I have tried this code but it won't focused back on where it was, it just back to the form but nothing is focused. void CMochikoshiDlg::OnOK() { // TODO: この位置にその他の検証用のコードを追加してください if ( m_edt_mochi_date_year.IsEmpty() || m_edt_mochi_date_month.IsEmpty() || m_edt_mochi_date_day.IsEmpty() ) { MessageBox( "Error" ); return; } CDialog::OnOK(); } How to do that? Thank you very much.
From: robert on 13 May 2008 04:30 You can use GetDlgItem to get the edit box by its id, then call SetFocus on it. Another way is that you can utilize dynamic data exchange of MFC to check if the data of one control is valid. Thanks Robert "Landon" <Landon(a)discussions.microsoft.com> д����Ϣ����:9B3F8997-1FC9-4722-9CC7-40EF4EA76E63(a)microsoft.com... >I have a form with 3 CEdit which are Year, Month and Day fields. > > If one of them is empty and user click OK or press Enter, an error message > will displayed and the focus will back on where it was. > > I have tried this code but it won't focused back on where it was, it just > back to the form but nothing is focused. > > void CMochikoshiDlg::OnOK() > { > // TODO: ����λ�äˤ�����Η��^�äΥ��`�ɤ��Ӥ��Ƥ��$��� > if ( m_edt_mochi_date_year.IsEmpty() || m_edt_mochi_date_month.IsEmpty() > || > m_edt_mochi_date_day.IsEmpty() ) { > MessageBox( "Error" ); > return; > } > CDialog::OnOK(); > } > > How to do that? > > Thank you very much.
From: Landon on 13 May 2008 05:24 > You can use GetDlgItem to get the edit box by its id, then call SetFocus on > it. > Another way is that you can utilize dynamic data exchange of MFC to check if > the data of one control is valid. > > Thanks > Robert Will it focus to the right CEdit control? I mean if there are 5 CEdit for example, when I was on the 3rd CEdit, I click OK or Enter then it should be back to CEdit number 3 right? Does the GetDlgItem make this possible? Thank you very much.
From: robert on 13 May 2008 05:53 Maybe you don't need to check its data until you click the OK button, and do that when the control lost the focus. This is some part of the idea of DDX. Otherwise, you need to save the last control with focus, right? "Landon" <Landon(a)discussions.microsoft.com> д����Ϣ����:AF41CFE3-F595-4552-BD53-3CCA204664CA(a)microsoft.com... >> You can use GetDlgItem to get the edit box by its id, then call SetFocus >> on >> it. >> Another way is that you can utilize dynamic data exchange of MFC to check >> if >> the data of one control is valid. >> >> Thanks >> Robert > > Will it focus to the right CEdit control? I mean if there are 5 CEdit for > example, when I was on the 3rd CEdit, I click OK or Enter then it should > be > back to CEdit number 3 right? Does the GetDlgItem make this possible? > > Thank you very much.
From: Landon on 13 May 2008 06:29 "robert" wrote: > Maybe you don't need to check its data until you click the OK button, and do > that when the control lost the focus. > This is some part of the idea of DDX. > Otherwise, you need to save the last control with focus, right? I don't understand with your explanation above, can you be more specific? According to you, how is the best way to solve my problem? Thank you very much.
|
Next
|
Last
Pages: 1 2 Prev: Remove title bar, but system menu still work Next: How to move focus / active control using Enter key? |