📄 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::Panel^ panel1;
protected:
private:
/// <summary>
/// 必需的设计器变量。
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
void InitializeComponent(void)
{
this->panel1 = (gcnew System::Windows::Forms::Panel());
this->SuspendLayout();
//
// panel1
//
this->panel1->Dock = System::Windows::Forms::DockStyle::Fill;
this->panel1->Location = System::Drawing::Point(0, 0);
this->panel1->Name = L"panel1";
this->panel1->Size = System::Drawing::Size(390, 214);
this->panel1->TabIndex = 0;
this->panel1->Paint += gcnew System::Windows::Forms::PaintEventHandler(this, &Form1::panel1_Paint);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(390, 214);
this->Controls->Add(this->panel1);
this->Name = L"Form1";
this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
this->Text = L"演示使用方向键浏览大图像";
this->KeyDown += gcnew System::Windows::Forms::KeyEventHandler(this, &Form1::Form1_KeyDown);
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
this->ResumeLayout(false);
}
#pragma endregion
public: Graphics^ MyGraphics,^MyBmpGraphics;
public: Bitmap^ MyBmp;
public: int MyXPos,MyYPos;
//绘制图像
private: System::Void panel1_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) {
if(this->MyBmp!=nullptr)
this->MyGraphics->DrawImage(MyBmp,MyXPos,MyYPos);
}
//装入图像
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
this->MyBmp=(Bitmap^)Image::FromFile(Application::StartupPath+"\\MyBitmap.jpg");
this->MyBmpGraphics=Graphics::FromImage(MyBmp);
this->MyGraphics=this->panel1->CreateGraphics();
this->MyXPos=0;
this->MyYPos=0;
this->panel1->Focus();
}
//通过方向键浏览图像
private: System::Void Form1_KeyDown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e) {
if (this->MyBmp == nullptr)
return;
switch(e->KeyValue)
{
case 37://LEFT ARROW(左箭头)键
if( MyXPos<0)
MyXPos=MyXPos+10;
break;
case 38://UP ARROW(上箭头)键
if(MyYPos<0)
MyYPos=MyYPos+10;
break;
case 39://RIGHT ARROW(右箭头)键
if(MyXPos>(-(MyBmp->Width-panel1->Width)))
MyXPos=MyXPos-10;
break;
case 40://DOWN ARROW(下箭头)键
if(MyYPos>(-(MyBmp->Height-panel1->Height)))
MyYPos=MyYPos-10;
break;
}
this->panel1->Refresh();
}
};
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -