構造一個能接收多位元字的輸入框

來源:互聯網
上載者:User

解決方案
可以通過指定Edwin editor的flags標記來限定使用者的輸入,輸入對話方塊的資源看起來如下:

 

Code:

DLG_LINE
{
type=EEikCtEdwin;
id=EMyQuery;

    control=EDWIN { maxlength=15; };
}
...
void CTestDlgDialog::PrepareLC(TInt aResourceId)
{
CEikDialog::PrepareLC( aResourceId );
// Dialog base class can be CAknDialog   

//CAknDialog::PrepareLC( aResourceId );
// Pick up the Editor control from the dialog
CEikEdwin* control = static_cast<CEikEdwin*>(ControlOrNull(EMyQuery));
// Set the input mode
control->SetAknEditorInputMode(EAknEditorNumericInputMode);
// Restrict the other input modes
control->SetAknEditorAllowedInputModes(EAknEditorNumericInputMode);
}上面的樣本提供給使用者一個可以輸入足夠位元數位對話方塊。
但是它也允許使用者輸入"*#pw+"這樣的字元——通過使用"*"或
"#"鍵,我們可以監控使用者的按鍵輸入來避免使用者輸入這些字元。
還可以顯示一個警告框提示使用者的非法輸入。OrCode:

RESOURCE DIALOG r_demo_data_query
{
flags = EGeneralQueryFlags;
buttons = R_AVKON_SOFTKEYS_OK_CANCEL;
items =
{
DLG_LINE
{
type = EAknCtQuery;
id = EGeneralQuery;
control = AVKON_DATA_QUERY
{
layout = EDataLayout;
label = ""; // prompt text
control = EDWIN
{
width = 5;
lines = 1;
maxlength = 15;
allowed_input_modes = EAknEditorNumericInputMode;
default_input_mode = EAknEditorNumericInputMode;
};
};
}
};
}

// The descriptor used for the editor
TBuf<128> text;
// The descriptor contained the prompt text for the query. The prompt // text can also be defined in the resource structure of the query
TBuf<128> prompt(_L("Enter data:"));
// create dialog instance
CAknTextQueryDialog* dlg =
new( ELeave ) CAknTextQueryDialog( text, prompt );
// Prepares the dialog, constructing it from the specified resource
dlg->PrepareLC( R_DEMO_DATA_QUERY );
// Sets the maximum length of the text editor
dlg->SetMaxLength(10);
// Launch the dialog
if (dlg->RunLD())
{
// ok pressed, text is the descriptor containing the entered text // in the editor.
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.