wxWidgets附加到wxChoice列表的站点 我为一个大学项目建立了一个基本的GUI,我使用WxWIDGET和CODBROCK,因为C++是我的舒适编程语言。但是,我想修改wxChoice上的选项,因为这些选项并不总是相同的,这意味着如果我在选项列表中添加了一些内容,然后我想将列表更新为一个完全不同的列表,首先我必须从选项列表中删除旧项,然后再添加新项,但是我找不到怎么做。这是我的密码: //Event void TestFrame::OnChoice1Select(wxCommandEvent& event) { fstream in; string str,str2; int i; //File where I store my list of lists in.open("Recursos/Carreras-LC.txt",ios::in); //Go to an specific line of the file where the list for the current choice is in=gotoLine(in,Choice1->GetSelection()+1); //Gets the line with the list getline(in,str,'\n'); in.close(); //Here is where I'll put the code to remove the current list of choices //My code to append the items from the list i got before i=0; while(str[i]!='\0'){ if(str[i]==','){ Choice2->Append(_(str2)); i++; str2=""; }else{ str2+=str[i]; i++; } } }
另外,如果有更好的方法来实现这种动态GUI,请告诉我。提前谢谢 我必须从选项列表中删除旧项,然后附加新项,但我找不到如何做 可以使用wxChoice::Clear()方法从选择控件中删除所有项,也可以使用wxChoice::Delete(unsigned int n)方法从控件中删除特定项 它们列在“从wxItemContainer继承的公共成员函数”部分的下面 另外,如果有更好的方法来实现这种动态GUI,请告诉我。提前谢谢 一个选项是使用,以便在主机架空闲时更新选项。如果你要走那条路,我会的wxWidgets附加到wxChoice列表的站点 我为一个大学项目建立了一个基本的GUI,我使用WxWIDGET和CODBROCK,因为C++是我的舒适编程语言。但是,我想修改wxChoice上的选项,因为这些选项并不总是相同的,这意味着如果我在选项列表中添加了一些内容,然后我想将列表更新为一个完全不同的列表,首先我必须从选项列表中删除旧项,然后再添加新项,但是我找不到怎么做。这是我的密码: //Event void TestFrame::OnChoice1Select(wxCommandEvent& event) { fstream in; string str,str2; int i; //File where I store my list of lists in.open("Recursos/Carreras-LC.txt",ios::in); //Go to an specific line of the file where the list for the current choice is in=gotoLine(in,Choice1->GetSelection()+1); //Gets the line with the list getline(in,str,'\n'); in.close(); //Here is where I'll put the code to remove the current list of choices //My code to append the items from the list i got before i=0; while(str[i]!='\0'){ if(str[i]==','){ Choice2->Append(_(str2)); i++; str2=""; }else{ str2+=str[i]; i++; } } },c++,append,codeblocks,wxwidgets,C++,Append,Codeblocks,Wxwidgets,另外,如果有更好的方法来实现这种动态GUI,请告诉我。提前谢谢 我必须从选项列表中删除旧项,然后附加新项,但我找不到如何做 可以使用wxChoice::Clear()方法从选择控件中删除所有项,也可以使用wxChoice::Delete(unsigned int n)方法从控件中删除特定项 它们列在“从wxItemContainer继承的公共成员函数”部分的下面 另外,如果有更好的方法来实现这种动态GUI,请告诉我。提前谢谢 一个选项是使用,以便在主机架空闲时更新选项。如果你要走那条路,我会的
m_choiceNeedsUpdate
或类似名称的bool成员和事件处理程序void onUpdate ui(wxUpdate UIEvent&event)
(或任何您想要调用的)添加到应用程序窗体的类中this->Bind(wxEVT_UPDATE_UI,&MyFrame::OnUpdateUI,this)的调用绑定框架构造函数中的事件处理程序代码>
m_choiceNeedsUpdate=true;
this->UpdateWindowUI();
void MyFrame::OnUpdateUI(wxUpdateUIEvent& event)
{
if (m_choiceNeedsUpdate)
{
//Update the choice control here (probably using the Clear/Delete methods)
m_choiceNeedsUpdate=false;
}
}
m_choiceNeedsUpdate
或类似名称的bool成员和事件处理程序void onUpdate ui(wxUpdate UIEvent&event)
(或任何您想要调用的)添加到应用程序窗体的类中this->Bind(wxEVT_UPDATE_UI,&MyFrame::OnUpdateUI,this)的调用绑定框架构造函数中的事件处理程序代码>
m_choiceNeedsUpdate=true;
this->UpdateWindowUI();
void MyFrame::OnUpdateUI(wxUpdateUIEvent& event)
{
if (m_choiceNeedsUpdate)
{
//Update the choice control here (probably using the Clear/Delete methods)
m_choiceNeedsUpdate=false;
}
}
缺点是,当您的框架运行时,会有很多对该事件处理程序的调用,这可能会影响性能。这就是为什么我在上面的示例中使用m_choiceNeedsUpdate bool变量来保护更改choice控件的逻辑。
wxEVT\u UPDATE\u UI
不是这样使用的,它应该直接更新控件,而不是设置标志。如果您这样做,那么直接使用wxEVT\u IDLE
就不会那么混乱了。wxEVT\u UPDATE\u UI
不是这样使用的,它应该直接更新控件,而不是设置标志。如果您只是这样做,那么直接使用wxEVT_IDLE
就不会那么混乱了。