语言

Menu
Sites
Language
TextBox selection

Hi

If i have two TextBox objects placed side by side and the user taps/clicks/touches on any one of them, then can i know which one he has selected or tapped on? Depending on that, i need to change its color so that it seems selected. Also can i change/set the value ont he text box at runtime, i mean on pressing some of button by the user? if yes please let me know how.

Thanks in advance.

编辑者为: Brock Boland 17 3月, 2014 原因: Paragraph tags added automatically from tizen_format_fix module.

响应

1 回复
Alex Dem
Hi, At first you could add pointers to both TextBoxes into your Form class description (where your controls are placed): Tizen::Ui::Controls::TextBox* __pTextBox1; Tizen::Ui::Controls::TextBox* __pTextBox2; You could create both TextBoxes using UI Builder and get pointers to both controls in yourForm::OnInitializing this way: __pTextBox1 = static_cast(GetControl(IDC_TEXTBOX1));... or you could construct TextBoxes in code like here: https://developer.tizen.org/help/index.jsp?topic=/org.tizen.native.apireference/classTizen_1_1Ui_1_1Controls_1_1TextBox.html 1) To determine focused TextBox use IFocusEventListener class. At first to register your TextBoxes this way: __pTextBox1->AddFocusEventListener(*this); __pTextBox2->AddFocusEventListener(*this); and reimplement virtual method OnFocusGained (const Tizen::Ui::Control &source); like this (in yourForm::OnInitializing): void yourForm::OnFocusGained(const Tizen::Ui::Control& source) { if (&source ==__pTextBox1) { //first TextBox in focus } else if (&source ==__pTextBox2) { //second TextBox in focus } } 2) To change Text/Background color of TextBox which in focus: If you have created TextBoxes with UI Builder you could set properties there for each element: - Highlighted Color - Highlighted text color for constructed in code TextBoxes you could use API : SetTextColor(TEXT_BOX_TEXT_COLOR_HIGHLIGHTED,Color::GetColor(COLOR_ID_GREEN)); SetColor(TEXT_BOX_STATUS_HIGHLIGHTED,Color::GetColor(COLOR_ID_BLUE)); 3) To update TextBox on button press you could use virtual reimplemented method OnActionPerformed of IActionEventListener class yourForm::OnActionPerformed { … __pTextBox2->SetText(L"MyText"); __pTextBox2->Invalidate(false); … } Alexey.