|
查看: 1610|回复: 9
|
visual c++ window form application picture viewer问题
[复制链接]
|
|
|
本帖最后由 尽善尽美 于 24-3-2011 07:25 PM 编辑
- #pragma once
- namespace pictureviewer {
- using namespace System;
- using namespace System::ComponentModel;
- using namespace System::Collections;
- using namespace System::Windows::Forms;
- using namespace System::Data;
- using namespace System::Drawing;
- /// <summary>
- /// Summary for Form1
- /// </summary>
- public ref class Form1 : public System::Windows::Forms::Form
- {
- public:
- Form1(void)
- {
- InitializeComponent();
- //
- //TODO: Add the constructor code here
- //
- }
- protected:
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- ~Form1()
- {
- if (components)
- {
- delete components;
- }
- }
- private: System::Windows::Forms::Button^ button1;
- protected:
- private: System::Windows::Forms::Button^ button2;
- private: System::Windows::Forms::Button^ button3;
- private: System::Windows::Forms::PictureBox^ pictureBox1;
- private: System::Windows::Forms::OpenFileDialog^ openFileDialog1;
- private:
- /// <summary>
- /// Required designer variable.
- /// </summary>
- System::ComponentModel::Container ^components;
- #pragma region Windows Form Designer generated code
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- void InitializeComponent(void)
- {
- this->button1 = (gcnew System::Windows::Forms::Button());
- this->button2 = (gcnew System::Windows::Forms::Button());
- this->button3 = (gcnew System::Windows::Forms::Button());
- this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
- this->openFileDialog1 = (gcnew System::Windows::Forms::OpenFileDialog());
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->BeginInit();
- this->SuspendLayout();
- //
- // button1
- //
- this->button1->Location = System::Drawing::Point(385, 12);
- this->button1->Name = L"button1";
- this->button1->Size = System::Drawing::Size(94, 23);
- this->button1->TabIndex = 0;
- this->button1->Text = L"Message Box";
- this->button1->UseVisualStyleBackColor = true;
- this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
- //
- // button2
- //
- this->button2->Location = System::Drawing::Point(385, 41);
- this->button2->Name = L"button2";
- this->button2->Size = System::Drawing::Size(94, 23);
- this->button2->TabIndex = 1;
- this->button2->Text = L"Change Color";
- this->button2->UseVisualStyleBackColor = true;
- this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
- //
- // button3
- //
- this->button3->Location = System::Drawing::Point(385, 70);
- this->button3->Name = L"button3";
- this->button3->Size = System::Drawing::Size(94, 23);
- this->button3->TabIndex = 2;
- this->button3->Text = L"Browse";
- this->button3->UseVisualStyleBackColor = true;
- this->button3->Click += gcnew System::EventHandler(this, &Form1::button3_Click);
- //
- // pictureBox1
- //
- this->pictureBox1->Location = System::Drawing::Point(12, 2);
- this->pictureBox1->Name = L"pictureBox1";
- this->pictureBox1->Size = System::Drawing::Size(367, 287);
- this->pictureBox1->TabIndex = 3;
- this->pictureBox1->TabStop = false;
- this->pictureBox1->Click += gcnew System::EventHandler(this, &Form1::pictureBox1_Click);
- //
- // openFileDialog1
- //
- this->openFileDialog1->FileName = L"openFileDialog1";
- this->openFileDialog1->Filter = L"Image|*.jpg;*.jpeg";
- this->openFileDialog1->FileOk += gcnew System::ComponentModel::CancelEventHandler(this, &Form1::openFileDialog1_FileOk);
- //
- // Form1
- //
- this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
- this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
- this->BackColor = System::Drawing::SystemColors::Control;
- this->ClientSize = System::Drawing::Size(491, 301);
- this->Controls->Add(this->pictureBox1);
- this->Controls->Add(this->button3);
- this->Controls->Add(this->button2);
- this->Controls->Add(this->button1);
- this->Name = L"Form1";
- this->Text = L"Picture Viewer";
- this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
- (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->EndInit();
- this->ResumeLayout(false);
- }
- #pragma endregion
- private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
- MessageBox::Show("Hello, World!"); }
- private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
- this->BackColor=Color::Red;
- }
- private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
- openFileDialog1->ShowDialog();
- pictureBox1->Load(openFileDialog1->FileName);
- }
- private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
- }
- private: System::Void openFileDialog1_FileOk(System::Object^ sender, System::ComponentModel::CancelEventArgs^ e) {
- }
- private: System::Void pictureBox1_Click(System::Object^ sender, System::EventArgs^ e) {
- }
- };
- }
复制代码
这是我的编程,我要做一个简单的picture viewer
按那个browse按键后,load picture就没事,但是如果你cancel就会出现这个,请问是什么问题? |
|
|
|
|
|
|
|
|
|
|
发表于 24-3-2011 08:24 PM
|
显示全部楼层
问题在这里。
108. this->openFileDialog1->FileName = L"openFileDialog1";
136. openFileDialog1->ShowDialog();
PictureBox1->Load(openFileDialog1->FileName);
你应该先检查 if (openFileDialog1->ShowDialog()==DialogResult::OK)
才做一下步骤。
PS: 别被自己的L"openFileDialog1",吓倒。 |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 24-3-2011 08:41 PM
|
显示全部楼层
问题在这里。
108. this->openFileDialog1->FileName = L"openFileDialog1";
136. openFileDialog1-> ...
chrizyuen2 发表于 24-3-2011 08:24 PM 
可以详细解释吗,我还是新手 |
|
|
|
|
|
|
|
|
|
|
发表于 24-3-2011 11:23 PM
|
显示全部楼层
可以详细解释吗,我还是新手
尽善尽美 发表于 24-3-2011 08:41 PM 
你按cancel, openFileDialog1->FileName 当然是原值。L"openFileDialog1";
没有这样的file存在,当然是 FileNotFoundException.
既然如此, 当然 , cancel时候就不执行
所以。 你应该先检查 if (openFileDialog1->ShowDialog()==DialogResult::OK)
才做一下步骤。 |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 25-3-2011 02:58 PM
|
显示全部楼层
你按cancel, openFileDialog1->FileName 当然是原值。L"openFileDialog1";
没有这样的file存在,当然是 ...
chrizyuen2 发表于 24-3-2011 11:23 PM 
- if(openFileDialog1->ShowDialog() ==
- System::Windows::Forms::DialogResult::OK)
- {
- pictureBox1->Load(openFileDialog1->FileName);
- }
复制代码
我把这个加进去了但还是一样情况 |
|
|
|
|
|
|
|
|
|
|
发表于 25-3-2011 03:04 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 25-3-2011 03:14 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 25-3-2011 03:16 PM
|
显示全部楼层
- if(openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK)
- {
- pictureBox1->Load(openFileDialog1->FileName);
- }
复制代码
这个也是可以 |
|
|
|
|
|
|
|
|
|
|
发表于 25-3-2011 03:35 PM
|
显示全部楼层
其实#5是对的,只是我打错东西
可否详细解释第五楼,老实说我的programming很差
尽善尽美 发表于 25-3-2011 03:14 PM 
我也猜不透,你什么不明白...看来要解释,就要从远古时代, 从非常basic说起,一直说到,你不明白的点.
可是,我没那时间.sorry. |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 25-3-2011 04:13 PM
|
显示全部楼层
我也猜不透,你什么不明白...看来要解释,就要从远古时代, 从非常basic说起,一直说到,你不明白的点.
...
chrizyuen2 发表于 25-3-2011 03:35 PM 
那谢谢你,我问其他人吧 |
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|