这就是我现在正在做的事情!!!
//picture box
pct->Click += gcnew EventHandler(this,&fornow::Form1::Display);
private: System::Void Display(System::Object^ sender, System::EventArgs^ e){
PictureBox^ pb = safe_cast<PictureBox^>(sender);
pictureBox1->Image = pb->Image;
}
显然我不能在 C++/Cli 中使用委托,我对这种编码很陌生!所以谁能告诉我点击后如何向事件处理程序方法发送更多参数,以便我可以在那里的代码中使用它!
就像我有一个 System::String 一样,如果我可以这样发送它,我可以写
private: System::Void Display(System::Object^ sender, System::EventArgs^ e, System::String^ s){
Mat img = imread(s);
imshow("",img);
waitKey(0);
}
我用 /clr 编译它,我使用试用版 vs 2010 Visual C++。
此代码驻留在 buttonclick 事件处理程序中...我添加了该部分代码...
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
// array<System::String^>^ files =
// System::IO::Directory::GetFiles(textBox1->Text,"*.*",
// System::IO::SearchOption::AllDirectories);
pin_ptr<const wchar_t> wch = PtrToStringChars(textBox1->Text);
wchar_t wch1[260];
wcscpy(wch1,wch);
list<basic_string<wchar_t>> dir;
list<string> s;
retrieve *r = new retrieve();
dir = r->print(wch1,dir);
for(list<basic_string<wchar_t>>::iterator itr = dir.begin(); itr != dir.end();itr++)
{
cout<<std::string(itr->begin(),itr->end())<<endl;
s.push_back(std::string(itr->begin(),itr->end()));
}
filter *f = new filter();
s=f->filter1(s); // fills s with paths (strings)
flowLayoutPanel1->Controls->Clear();
for(list<string>::iterator i=s.begin();i!=s.end();i++)
{
std::string sn = std::string(i->begin(),i->end());
System::String^ s = gcnew System::String(sn.c_str());
PictureBox^ pct = gcnew PictureBox();
if(checkBox1->Checked==true)
pct->Image = Image::FromFile(s)->GetThumbnailImage(50,50,nullptr,System::IntPtr::Zero);
if(checkBox1->Checked==false)
pct->Image = Image::FromFile(s);
pct->Size = System::Drawing::Size(100,100);
flowLayoutPanel1->Controls->Add(pct);
pct->Click += gcnew EventHandler(this,&fornow::Form1::Display);
Mat img = imread(sn);
imshow(sn,img);
waitKey(0);
}
对不起,我对这种编码真的很陌生..任何建议都会有所帮助,谢谢!!!