Hello Kira Qian,
thank you for your reply.
I need to create the Graphics object externally of the Paint event (into the FormLoad) because I have to access it into other routines (MouseMove for example...)
When resizing the form, I see that the VisibleClipBounds is not modified.
Here you can find the code
//MyForm.h
#pragma once
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
namespace MyProject {
public ref class MyForm : public System::Windows::Forms::Form
{
public:
MyForm(void)
{
InitializeComponent();
this->DoubleBuffered=true;
pMouse = gcnew array<PointF>(1);
mat=gcnew Matrix();
}
protected:
~MyForm()
{
if(components) delete components;
delete g;
}
private:
System::ComponentModel::Container ^components;
private: System::Windows::Forms::Label^ label1;
Graphics ^g;
System::Drawing::Drawing2D::Matrix ^mat;
array<PointF> ^pMouse;
#pragma region Windows Form Designer generated code
void InitializeComponent(void)
{
this->label1 = (gcnew System::Windows::Forms::Label());
this->SuspendLayout();
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(15, 10);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(35, 13);
this->label1->TabIndex = 0;
this->label1->Text = L"label1";
//
// MyForm
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(200, 200);
this->Controls->Add(this->label1);
this->Name = L"MyForm";
this->Text = L"MyForm";
this->Load += gcnew System::EventHandler(this, &MyForm::MyForm_Load);
this->Paint += gcnew System::Windows::Forms::PaintEventHandler(this, &MyForm::MyForm_Paint);
this->Resize += gcnew System::EventHandler(this, &MyForm::MyForm_Resize);
this->MouseMove += gcnew System::Windows::Forms::MouseEventHandler(this, &MyForm::MyForm_MouseMove);
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void MyForm_Load(System::Object^ sender, System::EventArgs^ e)
{
mat->Scale(0.5f, -0.5f);
mat->Translate(10.0f, -100.0f);
g = this->CreateGraphics();
g->PageUnit=GraphicsUnit::Pixel;
g->Transform=mat;
}
private: System::Void MyForm_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e)
{
g->Clear(Color::LightBlue);
// Draw ...
}
private: System::Void MyForm_Resize(System::Object^ sender, System::EventArgs^ e)
{
g->ResetClip();
g->SetClip(this->ClientRectangle);
}
private: System::Void MyForm_MouseMove(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e)
{
pMouse[0].X=(float)e->X;
pMouse[0].Y=(float)e->Y;
g->TransformPoints(CoordinateSpace::World, CoordinateSpace::Device, pMouse);
label1->Text="X, Y = "+pMouse[0].X.ToString("0.00")+", "+pMouse[0].Y.ToString("0.00"); //show world coordinate
}
};
}
thanks.