📄 form1.h
字号:
#pragma once
namespace Example {
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>
/// Form1 摘要
///
/// 警告: 如果更改此类的名称,则需要更改
/// 与此类所依赖的所有 .resx 文件关联的托管资源编译器工具的
/// “资源文件名”属性。否则,
/// 设计器将不能与此窗体的关联
/// 本地化资源正确交互。
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: 在此处添加构造函数代码
//
}
protected:
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::PictureBox^ pictureBox1;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::TextBox^ textBox1;
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::ProgressBar^ progressBar1;
private: System::Windows::Forms::Button^ button2;
protected:
private:
/// <summary>
/// 必需的设计器变量。
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
void InitializeComponent(void)
{
this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
this->label1 = (gcnew System::Windows::Forms::Label());
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->button1 = (gcnew System::Windows::Forms::Button());
this->label2 = (gcnew System::Windows::Forms::Label());
this->progressBar1 = (gcnew System::Windows::Forms::ProgressBar());
this->button2 = (gcnew System::Windows::Forms::Button());
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->BeginInit();
this->SuspendLayout();
//
// pictureBox1
//
this->pictureBox1->BorderStyle = System::Windows::Forms::BorderStyle::Fixed3D;
this->pictureBox1->Location = System::Drawing::Point(1, 2);
this->pictureBox1->Name = L"pictureBox1";
this->pictureBox1->Size = System::Drawing::Size(388, 169);
this->pictureBox1->TabIndex = 0;
this->pictureBox1->TabStop = false;
this->pictureBox1->LoadProgressChanged += gcnew System::ComponentModel::ProgressChangedEventHandler(this, &Form1::pictureBox1_LoadProgressChanged);
this->pictureBox1->LoadCompleted += gcnew System::ComponentModel::AsyncCompletedEventHandler(this, &Form1::pictureBox1_LoadCompleted);
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(2, 183);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(77, 12);
this->label1->TabIndex = 1;
this->label1->Text = L"图像文件名:";
//
// textBox1
//
this->textBox1->Location = System::Drawing::Point(85, 178);
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System::Drawing::Size(225, 21);
this->textBox1->TabIndex = 2;
//
// button1
//
this->button1->Location = System::Drawing::Point(314, 176);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(75, 23);
this->button1->TabIndex = 3;
this->button1->Text = L"装载图像";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// label2
//
this->label2->AutoSize = true;
this->label2->Location = System::Drawing::Point(2, 206);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(65, 12);
this->label2->TabIndex = 4;
this->label2->Text = L"装载进度:";
//
// progressBar1
//
this->progressBar1->Location = System::Drawing::Point(85, 200);
this->progressBar1->Name = L"progressBar1";
this->progressBar1->Size = System::Drawing::Size(225, 23);
this->progressBar1->TabIndex = 5;
//
// button2
//
this->button2->Location = System::Drawing::Point(314, 201);
this->button2->Name = L"button2";
this->button2->Size = System::Drawing::Size(75, 23);
this->button2->TabIndex = 6;
this->button2->Text = L"取消装载";
this->button2->UseVisualStyleBackColor = true;
this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(390, 225);
this->Controls->Add(this->button2);
this->Controls->Add(this->progressBar1);
this->Controls->Add(this->label2);
this->Controls->Add(this->button1);
this->Controls->Add(this->textBox1);
this->Controls->Add(this->label1);
this->Controls->Add(this->pictureBox1);
this->Name = L"Form1";
this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
this->Text = L"演示异步装载大图像文件";
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->EndInit();
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
//装载图像
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
OpenFileDialog^ MyDlg = gcnew OpenFileDialog();
MyDlg->Filter = "图像文件 (JPeg, Gif, Bmp, etc.)|*.jpg;*.jpeg;*.gif;*.bmp;*.tif; *.tiff; *.png| JPeg图像文件(*.jpg;*.jpeg)| *.jpg;*.jpeg |GIF图像文件(*.gif)|*.gif |BMP图像文件(*.bmp)|*.bmp|Tiff图像文件(*.tif;*.tiff)|*.tif;*.tiff|Png图像文件(*.png)| *.png |所有文件(*.*)|*.*";
MyDlg->CheckFileExists = true;
if (MyDlg->ShowDialog() == System::Windows::Forms::DialogResult::OK)
{
String^ MyFile = MyDlg->FileName;
this->textBox1->Text = MyFile;
this->pictureBox1->LoadAsync(MyFile);
}
}
//取消装载
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
this->pictureBox1->CancelAsync();
}
//显示图像文件装载进度
private: System::Void pictureBox1_LoadProgressChanged(System::Object^ sender, System::ComponentModel::ProgressChangedEventArgs^ e) {
this->progressBar1->Value = e->ProgressPercentage;
}
//显示图像文件装载结果
private: System::Void pictureBox1_LoadCompleted(System::Object^ sender, System::ComponentModel::AsyncCompletedEventArgs^ e) {
if (e->Error != nullptr)
{
MessageBox::Show(e->Error->Message, "信息提示", MessageBoxButtons::OK, MessageBoxIcon::Information);
}
else if ((e->Cancelled == true))
{
MessageBox::Show("异步装载图像操作被取消!", "信息提示", MessageBoxButtons::OK, MessageBoxIcon::Information);
}
else
{
MessageBox::Show("异步装载图像操作成功操作完成!", "信息提示", MessageBoxButtons::OK, MessageBoxIcon::Information);
}
}
};
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -