帮助我解决错误 [英] Help me with fixing error

查看:55
本文介绍了帮助我解决错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请大家帮忙解决此功能中的错误...

私人:System :: Void button1_Click(Object ^ sender,System :: EventArgs ^ e)

{
OpenFileDialog openFileDialog1 = gcnew OpenFileDialog;
this-> openFileDialog1 =(gcnew System :: Windows :: Forms :: OpenFileDialog());
//openFileDialog1-> ShowDialog;




this-> openFileDialog1-> Filter =图像(* .BMP; *.JPG; *.GIF,*.PNG,*.TIFF)| * .BMP; *.JPG; *.GIF; *.PNG; * .TIFF |"+所有文件(*.*)| *.*";


this-> openFileDialog1-> Multiselect = true;

this-> openFileDialog1->标题=选择位置";


DialogResult()dr = this-> openFileDialog1-> ShowDialog;

如果(dr = System :: Windows :: Forms :: DialogResult :: OK)

{
对于每个(openFileDialog1-> FileNames中的(System :: String ^文件)

{

试试

{

PictureBox imageControl = gcnew PictureBox();

imageControl.Height = 100;

imageControl.Width = 100;



图片:: GetThumbnailImageAbort ^ myCallback = gcnew图片:: GetThumbnailImageAbort(ThumbnailCallback);

位图myBitmap = gcnew位图(文件);

图片myThumbnail = myBitmap.GetThumbnailImage(96,96,myCallback(),IntPtr.Zero);

imageControl.Image = myThumbnail;


//PhotoGallery.Control.Add(imageControl);
this->控件-> Add(this-> imageControl);
}

catch(Exception ^ e)

{

MessageBox :: Show(e-> Message,"Error:",MessageBoxButtons :: OK,MessageBoxIcon :: Error);
//MessageBox :: Show(System :: String ^ Error);
}

}

}

}



公共:bool ThumbnailCallback()

{

返回false;

}

Could everyone please help he fixing error in this function...

private: System::Void button1_Click(Object^ sender, System::EventArgs^ e)

{
OpenFileDialog openFileDialog1 = gcnew OpenFileDialog;
this->openFileDialog1 = (gcnew System::Windows::Forms::OpenFileDialog());
//openFileDialog1->ShowDialog;




this->openFileDialog1->Filter = "Images (*.BMP;*.JPG;*.GIF,*.PNG,*.TIFF)|*.BMP;*.JPG;*.GIF;*.PNG;*.TIFF|" + "All files (*.*)|*.*";


this->openFileDialog1->Multiselect = true;

this->openFileDialog1->Title = "Select Location";


DialogResult() dr = this->openFileDialog1->ShowDialog;

if (dr = System::Windows::Forms::DialogResult::OK)

{
for each (System::String ^ file in openFileDialog1->FileNames)

{

try

{

PictureBox imageControl = gcnew PictureBox();

imageControl.Height = 100;

imageControl.Width = 100;



Image::GetThumbnailImageAbort ^ myCallback = gcnew Image::GetThumbnailImageAbort(ThumbnailCallback);

Bitmap myBitmap = gcnew Bitmap(file);

Image myThumbnail = myBitmap.GetThumbnailImage(96, 96, myCallback(), IntPtr.Zero);

imageControl.Image = myThumbnail;


//PhotoGallery.Control.Add(imageControl);
this->Controls->Add(this->imageControl);
}

catch (Exception^ e)

{

MessageBox::Show(e->Message, "Error: ", MessageBoxButtons::OK, MessageBoxIcon::Error);
//MessageBox::Show(System::String^ Error);
}

}

}

}



public: bool ThumbnailCallback()

{

return false;

}

推荐答案

必须为ShowDialog()(加括号).还有什么?
所有文本均为硬编码,无法使用string::Format而不是"+" ...

您对异常的处理是一个问题.您在本地处理它(不是很好的错误消息),然后完全阻止它向上传播.相反,您应该使用System::Windows::Forms::Application->OnThreadException.
在此处查看有关异常处理的更多详细信息:
我如何制作滚动条到达底部时将停止的循环 [当我运行应用程序时,异常是捕获了如何处理此问题? [
Must be ShowDialog() (add brackets). What else?
All texts are hard-coded, failure to use string::Format instead of "+"…

Your processing of exception is a problem. You process it locally (not very good error message) and then completely block its propagation up the stack. Instead, you should use System::Windows::Forms::Application->OnThreadException.
See more details on exception handling here:
How do i make a loop that will stop when a scrollbar reaches the bottom[^]
When i run an application an exception is caught how to handle this?[^]

No problem is reported.
Generally, such Questions are never answered. If you don''t report a problem, who will bother to look in your code. I just did, just for fun. :-)

—SA


这篇关于帮助我解决错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆