GDI+ How-To: Move the Origin

Introduction

The following code moves the origin from the top-left corner to the middle of the form

private: System::Void Form1_Paint(System::Object *  sender, System::Windows::Forms::PaintEventArgs *  e)
{
	 Matrix *mat = new Matrix(1, 0, 0, -1, 0, 0);
	 e->Graphics->Transform = mat;
	 e->Graphics->TranslateTransform(static_cast<float>(this->ClientSize.Width / 2), static_cast<float>(this->ClientSize.Height / 2), MatrixOrder::Append);

	 e->Graphics->DrawLine(Pens::Blue, -(this->ClientRectangle.Width / 2), 0, this->ClientRectangle.Width / 2, 0); 
	 e->Graphics->DrawLine(Pens::Blue, 0, -(this->ClientRectangle.Height / 2), 0, this->ClientRectangle.Height); 

	 e->Graphics->DrawLine(Pens::Yellow, 0, 0, 100, 100);
}
 

Home Copyright 2004 FunctionX, Inc.