所以我正在使用 WxDev 框架来开发我们程序的 GUI。 所以它有两个按钮,“上传”和“分析”。
顺序应该是用户上传图片。上传后,他可以单击“分析”按钮。现在,一旦他点击分析,我就想禁用它。只有在有新图像要分析时才会启用该按钮。
这是我拥有的按钮的代码,尽管它可能无关紧要。
上传:
void NBA_Jersey_RecognitionFrm::WxButton1Click(wxCommandEvent& event)
{
openIMGFileDialog->ShowModal();
if (openIMGFileDialog->GetPath().IsEmpty())
{
return;
}
imageopen = imgFile.LoadFile(openIMGFileDialog->GetPath(), wxBITMAP_TYPE_ANY);
int h = imgFile.GetHeight();
int w = imgFile.GetWidth();
pic.Create(w,h);
for (int x = 0; x < w; x++)
{
for (int y = 0; y < h; y++)
{
pic.SetRGB(x, y, 240, 240, 240);
}
}
if (300 >= (h*300/w))
{
displayIMG->SetBitmap(pic.Scale(300,h*300/w));
displayIMG->SetBitmap(imgFile.Scale(300,h*300/w));
}
else
{
displayIMG->SetBitmap(pic.Scale(w*300/h,300));
displayIMG->SetBitmap(imgFile.Scale(w*300/h,300));
}
}
这是我的 ANALYZE 按钮的摘录:
void NBA_Jersey_RecognitionFrm::WxButton1Click0(wxCommandEvent& event)
{
ofstream resultsFile;
stringstream ss;
string s;
int height = imgFile.GetHeight();
int width = imgFile.GetWidth();
RedVal = new int* [width];
GreenVal = new int* [width];
BlueVal= new int* [width];
for(int i=0; i<width; i++) {
RedVal[i] = new int[height];
GreenVal[i] = new int[height];
BlueVal[i] = new int[height];
}
//int RedVal[width][height];
//int GreenVal[width][height];
//int BlueVal[width][height];
resultsFile.open("results.txt");
//resultsFile << "x,y,Red,Green,Blue \n";
for(int h=0; h<height; h++) {
for(int w=0; w<width; w++) {
RedVal[w][h]=imgFile.GetRed(w,h);
GreenVal[w][h]=imgFile.GetGreen(w,h);
BlueVal[w][h]=imgFile.GetBlue(w,h);
//ss << h << "," << w << "," << RedVal[0][h] << "," << GreenVal[0][h] << "," << BlueVal[0][h] <<"\n";
//resultsFile << ss.str();
//resultsFile << h << "," << w << "," << RedVal[w][h] << "," << GreenVal[w][h] << "," << BlueVal[w][h] <<"\n";
}
}
WxDev C++ 中是否有关于禁用按钮的内置函数?或者我应该在我的代码中添加什么?谢谢。
最佳答案
您可以像这样禁用按钮(和大多数控件):
void NBA_Jersey_RecognitionFrm::WxButton1Click0(wxCommandEvent& event)
{
m_analyzeButton->Enable(false);
...
然后重新启用它:
void NBA_Jersey_RecognitionFrm::WxButton1Click(wxCommandEvent& event)
{
openIMGFileDialog->ShowModal();
if (openIMGFileDialog->GetPath().IsEmpty())
{
return;
}
m_analyzeButton->Enable(true);
...
将“m_analyzeButton”替换为您的按钮名称。
关于c++ - 禁用按钮功能(Wx 小部件),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42802139/