📄 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 __gc class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
}
protected:
void Dispose(Boolean disposing)
{
if (disposing && components)
{
components->Dispose();
}
__super::Dispose(disposing);
}
private: System::Windows::Forms::PictureBox * pictureBox1;
private: System::Windows::Forms::Button * button1;
private: System::Windows::Forms::Button * button2;
private: System::Windows::Forms::OpenFileDialog * openFileDialog1;
private:
/// <summary>
/// 必需的设计器变量。
/// </summary>
System::ComponentModel::Container * components;
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
void InitializeComponent(void)
{
System::Resources::ResourceManager * resources = new System::Resources::ResourceManager(__typeof(Example::Form1));
this->pictureBox1 = new System::Windows::Forms::PictureBox();
this->button1 = new System::Windows::Forms::Button();
this->button2 = new System::Windows::Forms::Button();
this->openFileDialog1 = new System::Windows::Forms::OpenFileDialog();
this->SuspendLayout();
//
// pictureBox1
//
this->pictureBox1->BorderStyle = System::Windows::Forms::BorderStyle::Fixed3D;
this->pictureBox1->Image = (__try_cast<System::Drawing::Image * >(resources->GetObject(S"pictureBox1.Image")));
this->pictureBox1->Location = System::Drawing::Point(0, 0);
this->pictureBox1->Name = S"pictureBox1";
this->pictureBox1->Size = System::Drawing::Size(352, 184);
this->pictureBox1->TabIndex = 0;
this->pictureBox1->TabStop = false;
//
// button1
//
this->button1->Location = System::Drawing::Point(48, 188);
this->button1->Name = S"button1";
this->button1->Size = System::Drawing::Size(96, 23);
this->button1->TabIndex = 1;
this->button1->Text = S"浏览图像";
this->button1->Click += new System::EventHandler(this, button1_Click);
//
// button2
//
this->button2->Location = System::Drawing::Point(192, 188);
this->button2->Name = S"button2";
this->button2->Size = System::Drawing::Size(96, 23);
this->button2->TabIndex = 2;
this->button2->Text = S"旋转图片";
this->button2->Click += new System::EventHandler(this, button2_Click);
//
// openFileDialog1
//
this->openFileDialog1->Filter = S"Image files (JPeg, Gif, Bmp, etc.)|*.jpg;*.jpeg;*.gif;*.bmp;*.tif; *.tiff; *.png|"
S" JPeg files (*.jpg;*.jpeg)|*.jpg;*.jpeg |GIF files (*.gif)|*.gif |BMP files (*.b"
S"mp)|*.bmp|Tiff files (*.tif;*.tiff)|*.tif;*.tiff|Png files (*.png)| *.png |All f"
S"iles (*.*)|*.*";
//
// Form1
//
this->AutoScaleBaseSize = System::Drawing::Size(6, 14);
this->ClientSize = System::Drawing::Size(344, 214);
this->Controls->Add(this->button2);
this->Controls->Add(this->button1);
this->Controls->Add(this->pictureBox1);
this->MaximizeBox = false;
this->Name = S"Form1";
this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
this->Text = S"演示旋转显示图片";
this->ResumeLayout(false);
}
private: System::Void button2_Click(System::Object * sender, System::EventArgs * e)
{//旋转图片
Graphics* g=this->pictureBox1->CreateGraphics();
g->Clear(Color::White);
//装入图片
Bitmap* MyImage=(Bitmap*)this->pictureBox1->Image;
//获取当前窗口的中心点
Rectangle MyRect=Rectangle(0,0,this->pictureBox1->get_Width(),this->pictureBox1->get_Height());
PointF MyCenter=PointF(MyRect.Width/2,MyRect.Height/2);
float MyOffsetX=0;
float MyOffsetY=0;
MyOffsetX=MyCenter.X-MyImage->get_Width()/2;
MyOffsetY=MyCenter.Y-MyImage->get_Height()/2;
//构造图片显示区域:让图片的中心点与窗口的中心点一致
RectangleF MyPicRect=RectangleF(MyOffsetX,MyOffsetY,MyImage->get_Width(),MyImage->get_Height());
PointF MyPointCenter=PointF(MyPicRect.X+MyPicRect.get_Width()/2,MyPicRect.Y+MyPicRect.get_Height()/2);
//让图片绕中心旋转一周
for(int iAngle=0; iAngle<361; iAngle+=1)
{
//g->Clear(Color::White);
// 绘图平面以图片的中心点旋转
g->TranslateTransform(MyPointCenter.X,MyPointCenter.Y);
g->RotateTransform( iAngle);
//恢复绘图平面在水平和垂直方向的平移
g->TranslateTransform(-MyPointCenter.X,-MyPointCenter.Y);
//绘制图片并延时
g->DrawImage(MyImage,MyPicRect);
System::Threading::Thread::Sleep(5);
//重置绘图平面的所有变换
g->ResetTransform();
}
}
private: System::Void button1_Click(System::Object * sender, System::EventArgs * e)
{//浏览图像
if(this->openFileDialog1->ShowDialog()==DialogResult::OK)
{
Image* MyImage=System::Drawing::Image::FromFile(this->openFileDialog1->FileName);
this->pictureBox1->Image=MyImage;
}
}
};
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -