SlideShare a Scribd company logo
C++.NET
Windows Forms Course
L08- GDI Part 1

Mohammad Shaker
mohammadshakergtr.wordpress.com
C++.NET Windows Forms Course
@ZGTRShaker
C++ Windows Forms L08 - GDI P1
GDI
- Part 1 -
What do u need to draw sth?
• Pen (stroke width, color, etc)
• Paper
• Brush to filling your drawing
Drawing::Graphic
• Encapsulates a GDI* + drawing surface.
• This class cannot be inherited.

___________________
• GDI* : Graphical Device Interface
Drawing::Graphics

private: System::Void button1_Click_5(System::Object^
sender, System::EventArgs^ e)
{
Drawing::Graphics ^MyGraphics;
MyGraphics = pictureBox1->CreateGraphics();
}
Drawing::Graphics
private void DrawImagePointF(PaintEventArgs e)
{
// Create image.
Image newImage = Image.FromFile("SampImag.jpg");
// Create point for upper-left corner of image.
PointF ulCorner = new PointF(100.0F, 100.0F);
// Draw image to screen.
e.Graphics.DrawImage(newImage, ulCorner);
}
Method
AddMetafileComment
BeginContainer()

Description

BeginContainer(Rectangle, Rectangle,
GraphicsUnit)

Adds a comment to the current Metafile.
Saves a graphics container with the current state of this Graphics and opens
and uses a new graphics container.
Saves a graphics container with the current state of this Graphics and opens
and uses a new graphics container with the specified scale transformation.

BeginContainer(RectangleF, RectangleF,
GraphicsUnit)

Saves a graphics container with the current state of this Graphics and opens
and uses a new graphics container with the specified scale transformation.

Clear

Clears the entire drawing surface and fills it with the specified background
color.
Performs a bit-block transfer of color data, corresponding to a rectangle of
pixels, from the screen to the drawing surface of the Graphics.

CopyFromScreen(Point, Point, Size)
CopyFromScreen(Point, Point, Size,
CopyPixelOperation)

Performs a bit-block transfer of color data, corresponding to a rectangle of
pixels, from the screen to the drawing surface of the Graphics.

CopyFromScreen(Int32, Int32, Int32, Int32,
Size)

Performs a bit-block transfer of the color data, corresponding to a rectangle of
pixels, from the screen to the drawing surface of the Graphics.

CopyFromScreen(Int32, Int32, Int32, Int32,
Size, CopyPixelOperation)

Performs a bit-block transfer of the color data, corresponding to a rectangle of
pixels, from the screen to the drawing surface of the Graphics.

CreateObjRef

Creates an object that contains all the relevant information required to
generate a proxy used to communicate with a remote object. (Inherited
fromMarshalByRefObject.)
Releases all resources used by this Graphics.
Draws an arc representing a portion of an ellipse specified by
a Rectangle structure.
Draws an arc representing a portion of an ellipse specified by a RectangleF

Dispose
DrawArc(Pen, Rectangle, Single, Single)

DrawArc(Pen, RectangleF, Single, Single)
DrawArc(Pen, Int32, Int32, Int32, Int32, Int32, Int32) Draws an arc representing a portion of an ellipse specified by a pair of coordinates, a width,
and a height.
DrawArc(Pen, Single, Single, Single, Single, Single,
Single)

Draws an arc representing a portion of an ellipse specified by a pair of coordinates, a width,
and a height.

DrawBezier(Pen, Point, Point, Point, Point)

Draws a Bézier spline defined by four Point structures.

DrawBezier(Pen, PointF, PointF, PointF, PointF)

Draws a Bézier spline defined by four PointF structures.

DrawBezier(Pen, Single, Single, Single, Single, Single, Draws a Bézier spline defined by four ordered pairs of coordinates that represent points.
Single, Single, Single)
DrawBeziers(Pen, Point[])
Draws a series of Bézier splines from an array of Point structures.
DrawBeziers(Pen, PointF[])

Draws a series of Bézier splines from an array of PointF structures.

DrawClosedCurve(Pen, Point[])

Draws a closed cardinal spline defined by an array of Point structures.

DrawClosedCurve(Pen, PointF[])

Draws a closed cardinal spline defined by an array of PointF structures.

DrawClosedCurve(Pen, Point[], Single, FillMode)

Draws a closed cardinal spline defined by an array of Point structures using a specified
tension.

DrawClosedCurve(Pen, PointF[], Single, FillMode)

Draws a closed cardinal spline defined by an array of PointF structures using a specified
tension.

DrawCurve(Pen, Point[])

Draws a cardinal spline through a specified array of Point structures.

DrawCurve(Pen, PointF[])

Draws a cardinal spline through a specified array of PointF structures.

DrawCurve(Pen, Point[], Single)

Draws a cardinal spline through a specified array of Point structures using a specified tension.
DrawCurve(Pen, PointF[], Single)
DrawCurve(Pen, PointF[], Int32, Int32)

Draws a cardinal spline through a specified array of PointF structures using a
specified tension.
Draws a cardinal spline through a specified array of PointF structures. The
drawing begins offset from the beginning of the array.

DrawCurve(Pen, Point[], Int32, Int32, Single)

Draws a cardinal spline through a specified array of Point structures using a
specified tension.
DrawCurve(Pen, PointF[], Int32, Int32, Single) Draws a cardinal spline through a specified array of PointF structures using a
specified tension. The drawing begins offset from the beginning of the array.
DrawEllipse(Pen, Rectangle)

Draws an ellipse specified by a bounding Rectangle structure.

DrawEllipse(Pen, RectangleF)
DrawEllipse(Pen, Int32, Int32, Int32, Int32)

Draws an ellipse defined by a bounding RectangleF.
Draws an ellipse defined by a bounding rectangle specified by coordinates for
the upper-left corner of the rectangle, a height, and a width.

DrawEllipse(Pen, Single, Single, Single, Single) Draws an ellipse defined by a bounding rectangle specified by a pair of
coordinates, a height, and a width.
DrawIcon(Icon, Rectangle)
Draws the image represented by the specified Icon within the area specified
by aRectangle structure.
DrawIcon(Icon, Int32, Int32)
DrawIconUnstretched
DrawImage(Image, Point)
DrawImage(Image, Point[])

Draws the image represented by the specified Icon at the specified
coordinates.
Draws the image represented by the specified Icon without scaling the image.
Draws the specified Image, using its original physical size, at the specified
location.
Draws the specified Image at the specified location and with the specified
shape
System::Drawing
System::Drawing
• Graphics Class :
– Can’t be inherited

• Inheritance Hierarchy :
– System::Object
System::MarshalByRefObject
System.Drawing::Graphics
Drawing::Point
• What will happen now?
private: System::Void button1_Click(System::Object^
sender, System::EventArgs^ e)
{
button1->Location = 30,120;
}
Drawing::Point
Drawing::Point
• What will happen now?
private: System::Void button1_Click(System::Object^
System::EventArgs^ e)
{
Drawing::Point P;
P.X = 2;
P.Y = 23;
button1->Location = P;
}

sender,
Drawing::Point
Changing the size of the form at
run time

So, what should
we do?
Drawing::Size
• Can we do this? Form’s size?
private: System::Void button1_Click_1(System::Object^
System::EventArgs^ e)
{
Drawing::Size S;
S.Height = 200;
S.Width = 300;
this->Size = S;
}

Yep!

sender,
Drawing::Size
• Can we do this?
private: System::Void button1_Click_1(System::Object^
System::EventArgs^ e)
{
Drawing::Size ^S;
S->Height = 200;
S->Width = 300;
this->Size = S;
}

sender,

Compile error

Error
1
error C2664: 'void
System::Windows::Forms::Control::Size::set(System::Drawing::Size)'
: cannot convert parameter 1 from 'System::Drawing::Size ^' to
'System::Drawing::Size'
c:userszgtrdocumentsvisual studio
2008projectsdotnet4dotnet4Form1.h 129
dotNet4
C++ Windows Forms L08 - GDI P1
Drawing::Size
• Do this:
private: System::Void button1_Click_1(System::Object^
sender, System::EventArgs^ e)
{
this->Size = Drawing::Size(200,300);
}

• Or Add Drawing in using
C++ Windows Forms L08 - GDI P1
Drawing::Size
System::Drawing::Pen
private: System::Void button1_Click_5(System::Object^ sender,
System::EventArgs^ e)
{
System::Drawing::Pen ^ MyPen = gcnew Pen(Color::Red);
}
C++ Windows Forms L08 - GDI P1
C++ Windows Forms L08 - GDI P1
Let’s draw a line!
Graphics.DrawLine() Method
private: System::Void button1_Click_5(System::Object^
System::EventArgs^ e)
{
System::Drawing::Graphics::DrawLine(
}

sender,
C++ Windows Forms L08 - GDI P1
System::Drawing::Pen
private: System::Void button1_Click_5(System::Object^ sender,
System::EventArgs^ e)
{
System::Drawing::Pen ^ MyPen = gcnew Pen(Color::Red);
Drawing::Graphics::DrawLine( MyPen, 2, 3, 4,5 );
}
Graphics.DrawLine Method
•
•
•
•

public: void DrawLine(Pen*, Point, Point);
public: void DrawLine(Pen*, PointF, PointF);
public: void DrawLine(Pen*, int, int, int, int);
public: void DrawLine(Pen*, float, float, float, float);
C++ Windows Forms L08 - GDI P1
C++ Windows Forms L08 - GDI P1
System::Drawing
• What will happen now?
private: System::Void button1_Click_5(System::Object^ sender,
System::EventArgs^ e)
{
System::Drawing::Pen ^ MyPen = gcnew Pen(Color::Red);
Drawing::Graphics::DrawLine( MyPen, 2, 3, 4,5 );
}

Compiler error ..
C++ Windows Forms L08 - GDI P1
System::Drawing
• What will happen now?
private: System::Void button1_Click_5(System::Object^ sender,
System::EventArgs^ e)
{
System::Drawing::Pen ^ MyPen = gcnew Pen(Color::Red);
Drawing::Graphics ^MyGraphics;
MyGraphics->DrawLine( MyPen, 2, 3, 4,5 );
}
No compiler error but Runtime error when clicking button1
C++ Windows Forms L08 - GDI P1
System::Drawing
• What will happen now?
private: System::Void button1_Click_5(System::Object^ sender, System::EventArgs^
e)
{
System::Drawing::Pen ^ MyPen = gcnew Pen(Color::Red);
Drawing::Graphics ^MyGraphics;
MyGraphics = pictureBox1->CreateGraphics();
MyGraphics->DrawLine( MyPen, 2, 3, 50,105 );
}

A line will be drawn!
System::Drawing
• After clicking the button
System::Drawing
• Can we do this?
private: System::Void button1_Click_5(System::Object^ sender,
System::EventArgs^ e)
{
Drawing::Graphics ^MyGraphics;
MyGraphics = pictureBox1->CreateGraphics();
MyGraphics->DrawLine(System::Drawing::Pen(Color::Red),2,3,50,105);
}

Compiler error
C++ Windows Forms L08 - GDI P1
System::Drawing
• Can we do this?
private: System::Void button1_Click_5(System::Object^
System::EventArgs^ e)
{
System::Drawing::Pen MyPen();
MyPen.Color = Color::Red;
Drawing::Graphics ^MyGraphics;
MyGraphics = pictureBox1->CreateGraphics();
MyGraphics->DrawLine(MyPen, 2, 3, 50,105 );
}
Compiler error

sender,
C++ Windows Forms L08 - GDI P1
System::Drawing
• Can we do this?
private: System::Void button1_Click_5(System::Object^
System::EventArgs^ e)
{
System::Drawing::Pen MyPen(Color::Red );
Drawing::Graphics ^MyGraphics;
MyGraphics = pictureBox1->CreateGraphics();
MyGraphics->DrawLine(MyPen, 2, 3, 50,105 );
}
Compiler error

sender,
C++ Windows Forms L08 - GDI P1
System::Drawing
• Can we do this?
private: System::Void button1_Click_5(System::Object^
System::EventArgs^ e)
{
System::Drawing::Pen ^MyPen(Color::Red);
Drawing::Graphics ^MyGraphics;
MyGraphics = pictureBox1->CreateGraphics();
MyGraphics->DrawLine(MyPen, 2, 3, 50,105 );
}
Compiler error!

sender,
C++ Windows Forms L08 - GDI P1
System::Drawing
• Can we do this?
private: System::Void button1_Click_5(System::Object^
System::EventArgs^ e)
{
System::Drawing::Pen ^MyPen = gcnew Pen;
Drawing::Graphics ^MyGraphics;
MyGraphics = pictureBox1->CreateGraphics();
MyGraphics->DrawLine(MyPen, 2, 3, 50,105 );
}
Compiler error

sender,
C++ Windows Forms L08 - GDI P1
System::Drawing
• Can we do this?
private: System::Void button1_Click_5(System::Object^ sender,
System::EventArgs^ e)
{
System::Drawing::Color ^MyColor = gcnew Color;
MyColor = Drawing::Color::Red;
System::Drawing::Pen ^MyPen = gcnew Pen(*MyColor);
Drawing::Graphics ^MyGraphics;
MyGraphics = pictureBox1->CreateGraphics();
MyGraphics->DrawLine(MyPen, 2, 3, 50,105 );
}
Working!
System::Drawing
• Can we do this?
private: System::Void button1_Click_5(System::Object^ sender,
System::EventArgs^ e)
{
System::Drawing::Color ^MyColor = gcnew Color; // 1
MyColor = Drawing::Color::Red;
// 2
System::Drawing::Pen ^MyPen = gcnew Pen(MyColor); // 3
Drawing::Graphics ^MyGraphics;
MyGraphics = pictureBox1->CreateGraphics();
MyGraphics->DrawLine(MyPen, 2, 3, 50,105 );
}
Compiler error in // 3
System::Drawing
• Can we do this?
private: System::Void button1_Click_5(System::Object^ sender,
System::EventArgs^ e)
{
System::Drawing::Color MyColor = gcnew Color; // 1
MyColor = Drawing::Color::Red;
// 2
System::Drawing::Pen ^MyPen = gcnew Pen(*MyColor); // 3
Drawing::Graphics ^MyGraphics;
MyGraphics = pictureBox1->CreateGraphics();
MyGraphics->DrawLine(MyPen, 2, 3, 50,105 );
}
Compiler error in // 1 . ^
System::Drawing
• Can we do this?
private: System::Void button1_Click_5(System::Object^ sender,
System::EventArgs^ e)
{
System::Drawing::Color ^MyColor = gcnew Color; // 1
MyColor = Red;
// 2
System::Drawing::Pen ^MyPen = gcnew Pen(*MyColor); // 3
Drawing::Graphics ^MyGraphics;
MyGraphics = pictureBox1->CreateGraphics();
MyGraphics->DrawLine(MyPen, 2, 3, 50,105 );
}
Compiler error in // 2

un-declared Red
System::Drawing
• But remember we can just do this
private: System::Void button1_Click_5(System::Object^ sender,
System::EventArgs^ e)
{
System::Drawing::Pen ^ MyPen = gcnew Pen(Color::Red);
Drawing::Graphics ^MyGraphics;
MyGraphics = pictureBox1->CreateGraphics();
MyGraphics->DrawLine( MyPen, 2, 3, 50,105 );
}
System::Drawing
• Another way!
private: System::Void button1_Click_5(System::Object^ sender,
System::EventArgs^ e)
{
System::Drawing::Pen ^ MyPen = gcnew Pen(Color::Red);
Drawing::Graphics ^MyGraphics;
MyGraphics = pictureBox1->CreateGraphics();
Drawing::Point ^P1 = gcnew Point(50,60);
Drawing::Point ^P2 = gcnew Point(150,160);
MyGraphics->DrawLine( MyPen, *P1, *P2 );
}
What will happen?
System::Drawing
System::Drawing
• Another way!
private: System::Void button1_Click_5(System::Object^ sender,
System::EventArgs^ e)
{
System::Drawing::Pen ^ MyPen = gcnew Pen(Color::Red);
Drawing::Graphics ^MyGraphics;
MyGraphics = pictureBox1->CreateGraphics();
Drawing::Point P1 = gcnew Point(50,60);
Drawing::Point P2 = gcnew Point(150,160);
MyGraphics->DrawLine( MyPen, *P1, *P2 );
}
What will happen?
Compiler error
System::Drawing
• Another way!
private: System::Void button1_Click_5(System::Object^ sender,
System::EventArgs^ e)
{
System::Drawing::Pen ^ MyPen = gcnew Pen(Color::Red);
Drawing::Graphics ^MyGraphics;
MyGraphics = pictureBox1->CreateGraphics();
Drawing::Point P1 = gcnew Point(50,60);
Drawing::Point P2 = gcnew Point(150,160);
MyGraphics->DrawLine( MyPen, P1, P2 );
}
What will happen?
Compiler error
System::Drawing
• Can we do this?
private: System::Void button1_Click_5(System::Object^ sender,
System::EventArgs^ e)
{
System::Drawing::Pen ^ MyPen = gcnew Pen(Color::Red);
Drawing::Graphics ^MyGraphics;
MyGraphics = pictureBox1->CreateGraphics();
Drawing::Point P1(50,60);
Drawing::Point P2(150,160);
MyGraphics->DrawLine( MyPen, P1, P2 );
}
Works!
System::Drawing
• Sth wrong?
private: System::Void button1_Click_5(System::Object^ sender,
System::EventArgs^ e)
{
System::Drawing::Pen ^ MyPen = gcnew Pen(Color::Red);
Drawing::Graphics ^MyGraphics;
MyGraphics = pictureBox1->CreateGraphics();
Drawing::Point P1; P1.X = 50; P1.Y = 60;
Drawing::Point P2; P2.X = 150; P2.Y = 160;
MyGraphics->DrawLine( MyPen, P1, P2 );
}
Works!
System::Drawing
• What will happen now?
private: System::Void button1_Click_5(System::Object^ sender,
System::EventArgs^ e)
{
System::Drawing::Pen ^ MyPen = gcnew Pen(Color::Red);
Drawing::Graphics ^MyGraphics;
MyGraphics = pictureBox1->CreateGraphics();
Drawing::Point P1, P2;
P1.X = 50; P1.Y = 60;
P2.X = 150; P2.Y = 160;
MyGraphics->DrawLine( MyPen, P1, P2 );
P1.X = 50; P1.Y = 60;
P2.X = 510; P2.Y = 610;
MyGraphics->DrawLine( MyPen, P1, P2 );
}
System::Drawing
• What’s missing? Next Lesson we’ll find out!
Mouse!
private: System::Void panel1_MouseClick(System::Object^ sender,
System::Windows::Forms::MouseEventArgs^ e)
{
System::Drawing::Point P(0,0);
MyGraphics->DrawEllipse(MyPen,e->X,e->Y,10,10);
MyGraphics->FillEllipse(MyBrush,e->X,e->Y,10,10);
}
That’s it for today!

More Related Content

PDF
C++ Windows Forms L03 - Controls P2
PPT
Csphtp1 09
PPS
CS101- Introduction to Computing- Lecture 35
PDF
The Ring programming language version 1.3 book - Part 83 of 88
PDF
The Ring programming language version 1.3 book - Part 38 of 88
PPTX
Type script by Howard
PPTX
TypeScript by Howard
PDF
The Ring programming language version 1.6 book - Part 183 of 189
C++ Windows Forms L03 - Controls P2
Csphtp1 09
CS101- Introduction to Computing- Lecture 35
The Ring programming language version 1.3 book - Part 83 of 88
The Ring programming language version 1.3 book - Part 38 of 88
Type script by Howard
TypeScript by Howard
The Ring programming language version 1.6 book - Part 183 of 189

What's hot (19)

PDF
The Ring programming language version 1.5.3 book - Part 48 of 184
PDF
The Ring programming language version 1.3 book - Part 5 of 88
PDF
The Ring programming language version 1.6 book - Part 32 of 189
PPTX
Gui programming
PPTX
PDF
The Ring programming language version 1.5.3 book - Part 30 of 184
PDF
2 BytesC++ course_2014_c9_ pointers and dynamic arrays
PPTX
My favorite slides
PDF
PART 6: FROM GEO INTO YOUR REPORT
PPTX
Presentation1 computer shaan
PDF
Cc code cards
PPT
Csphtp1 07
PPTX
Yin Yangs of Software Development
PPT
Python GUI Programming
PDF
R-Shiny Cheat sheet
PDF
PART 5: RASTER DATA
PPTX
PYTHON - EXTRA Chapter GUI - MAULIK BORSANIYA
PDF
03 Geographic scripting in uDig - halfway between user and developer
PDF
OpenVX 1.0 Reference Guide
The Ring programming language version 1.5.3 book - Part 48 of 184
The Ring programming language version 1.3 book - Part 5 of 88
The Ring programming language version 1.6 book - Part 32 of 189
Gui programming
The Ring programming language version 1.5.3 book - Part 30 of 184
2 BytesC++ course_2014_c9_ pointers and dynamic arrays
My favorite slides
PART 6: FROM GEO INTO YOUR REPORT
Presentation1 computer shaan
Cc code cards
Csphtp1 07
Yin Yangs of Software Development
Python GUI Programming
R-Shiny Cheat sheet
PART 5: RASTER DATA
PYTHON - EXTRA Chapter GUI - MAULIK BORSANIYA
03 Geographic scripting in uDig - halfway between user and developer
OpenVX 1.0 Reference Guide
Ad

Similar to C++ Windows Forms L08 - GDI P1 (20)

PDF
C++ Windows Forms L09 - GDI P2
PPT
Chapter 13
PPT
Introduction_to_AUTOCAD (DESIGN BY COMPUTER).ppt
DOC
Java applet handouts
DOCX
On the tomcat drive in folder cosc210 you will find file named Paint.docx
PDF
Intake 37 6
PDF
Intake 38 6
PDF
Delphi L06 GDI Drawing
PDF
Cg lab cse-v (1) (1)
PDF
XNA L04–Primitives, IndexBuffer and VertexBuffer
PPTX
AutoCAD-ppt_ training report summer .pptx
PDF
XNA L09–2D Graphics and Particle Engines
PPT
Basic_Introduction_to_AUTOCAD.ppt
PPTX
AutoCAD-ppt.pptx
PPTX
AutoCAD-ppt.pptx
PPTX
AutoCAD-ppt.pptx
PPTX
mech AutoCAD ppt.pptx
PPTX
GeoGebra 10
PPTX
FLA AUTO CAD 202.pptxhhcccbbvgggvgggvchjhh
DOCX
asmt7~$sc_210_-_assignment_7_fall_15.docasmt7cosc_210_-_as.docx
C++ Windows Forms L09 - GDI P2
Chapter 13
Introduction_to_AUTOCAD (DESIGN BY COMPUTER).ppt
Java applet handouts
On the tomcat drive in folder cosc210 you will find file named Paint.docx
Intake 37 6
Intake 38 6
Delphi L06 GDI Drawing
Cg lab cse-v (1) (1)
XNA L04–Primitives, IndexBuffer and VertexBuffer
AutoCAD-ppt_ training report summer .pptx
XNA L09–2D Graphics and Particle Engines
Basic_Introduction_to_AUTOCAD.ppt
AutoCAD-ppt.pptx
AutoCAD-ppt.pptx
AutoCAD-ppt.pptx
mech AutoCAD ppt.pptx
GeoGebra 10
FLA AUTO CAD 202.pptxhhcccbbvgggvgggvchjhh
asmt7~$sc_210_-_assignment_7_fall_15.docasmt7cosc_210_-_as.docx
Ad

More from Mohammad Shaker (20)

PDF
12 Rules You Should to Know as a Syrian Graduate
PDF
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
PDF
Interaction Design L06 - Tricks with Psychology
PDF
Short, Matters, Love - Passioneers Event 2015
PDF
Unity L01 - Game Development
PDF
Android L07 - Touch, Screen and Wearables
PDF
Interaction Design L03 - Color
PDF
Interaction Design L05 - Typography
PDF
Interaction Design L04 - Materialise and Coupling
PDF
Android L05 - Storage
PDF
Android L04 - Notifications and Threading
PDF
Android L09 - Windows Phone and iOS
PDF
Interaction Design L01 - Mobile Constraints
PDF
Interaction Design L02 - Pragnanz and Grids
PDF
Android L10 - Stores and Gaming
PDF
Android L06 - Cloud / Parse
PDF
Android L08 - Google Maps and Utilities
PDF
Android L03 - Styles and Themes
PDF
Android L02 - Activities and Adapters
PDF
Android L01 - Warm Up
12 Rules You Should to Know as a Syrian Graduate
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
Interaction Design L06 - Tricks with Psychology
Short, Matters, Love - Passioneers Event 2015
Unity L01 - Game Development
Android L07 - Touch, Screen and Wearables
Interaction Design L03 - Color
Interaction Design L05 - Typography
Interaction Design L04 - Materialise and Coupling
Android L05 - Storage
Android L04 - Notifications and Threading
Android L09 - Windows Phone and iOS
Interaction Design L01 - Mobile Constraints
Interaction Design L02 - Pragnanz and Grids
Android L10 - Stores and Gaming
Android L06 - Cloud / Parse
Android L08 - Google Maps and Utilities
Android L03 - Styles and Themes
Android L02 - Activities and Adapters
Android L01 - Warm Up

Recently uploaded (20)

PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Approach and Philosophy of On baking technology
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Encapsulation theory and applications.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPT
Teaching material agriculture food technology
PDF
Machine learning based COVID-19 study performance prediction
PDF
cuic standard and advanced reporting.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
MYSQL Presentation for SQL database connectivity
The Rise and Fall of 3GPP – Time for a Sabbatical?
NewMind AI Weekly Chronicles - August'25 Week I
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Approach and Philosophy of On baking technology
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
“AI and Expert System Decision Support & Business Intelligence Systems”
Reach Out and Touch Someone: Haptics and Empathic Computing
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Mobile App Security Testing_ A Comprehensive Guide.pdf
Encapsulation theory and applications.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Encapsulation_ Review paper, used for researhc scholars
20250228 LYD VKU AI Blended-Learning.pptx
Teaching material agriculture food technology
Machine learning based COVID-19 study performance prediction
cuic standard and advanced reporting.pdf
Chapter 3 Spatial Domain Image Processing.pdf

C++ Windows Forms L08 - GDI P1

  • 1. C++.NET Windows Forms Course L08- GDI Part 1 Mohammad Shaker mohammadshakergtr.wordpress.com C++.NET Windows Forms Course @ZGTRShaker
  • 4. What do u need to draw sth? • Pen (stroke width, color, etc) • Paper • Brush to filling your drawing
  • 5. Drawing::Graphic • Encapsulates a GDI* + drawing surface. • This class cannot be inherited. ___________________ • GDI* : Graphical Device Interface
  • 6. Drawing::Graphics private: System::Void button1_Click_5(System::Object^ sender, System::EventArgs^ e) { Drawing::Graphics ^MyGraphics; MyGraphics = pictureBox1->CreateGraphics(); }
  • 7. Drawing::Graphics private void DrawImagePointF(PaintEventArgs e) { // Create image. Image newImage = Image.FromFile("SampImag.jpg"); // Create point for upper-left corner of image. PointF ulCorner = new PointF(100.0F, 100.0F); // Draw image to screen. e.Graphics.DrawImage(newImage, ulCorner); }
  • 8. Method AddMetafileComment BeginContainer() Description BeginContainer(Rectangle, Rectangle, GraphicsUnit) Adds a comment to the current Metafile. Saves a graphics container with the current state of this Graphics and opens and uses a new graphics container. Saves a graphics container with the current state of this Graphics and opens and uses a new graphics container with the specified scale transformation. BeginContainer(RectangleF, RectangleF, GraphicsUnit) Saves a graphics container with the current state of this Graphics and opens and uses a new graphics container with the specified scale transformation. Clear Clears the entire drawing surface and fills it with the specified background color. Performs a bit-block transfer of color data, corresponding to a rectangle of pixels, from the screen to the drawing surface of the Graphics. CopyFromScreen(Point, Point, Size) CopyFromScreen(Point, Point, Size, CopyPixelOperation) Performs a bit-block transfer of color data, corresponding to a rectangle of pixels, from the screen to the drawing surface of the Graphics. CopyFromScreen(Int32, Int32, Int32, Int32, Size) Performs a bit-block transfer of the color data, corresponding to a rectangle of pixels, from the screen to the drawing surface of the Graphics. CopyFromScreen(Int32, Int32, Int32, Int32, Size, CopyPixelOperation) Performs a bit-block transfer of the color data, corresponding to a rectangle of pixels, from the screen to the drawing surface of the Graphics. CreateObjRef Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited fromMarshalByRefObject.) Releases all resources used by this Graphics. Draws an arc representing a portion of an ellipse specified by a Rectangle structure. Draws an arc representing a portion of an ellipse specified by a RectangleF Dispose DrawArc(Pen, Rectangle, Single, Single) DrawArc(Pen, RectangleF, Single, Single)
  • 9. DrawArc(Pen, Int32, Int32, Int32, Int32, Int32, Int32) Draws an arc representing a portion of an ellipse specified by a pair of coordinates, a width, and a height. DrawArc(Pen, Single, Single, Single, Single, Single, Single) Draws an arc representing a portion of an ellipse specified by a pair of coordinates, a width, and a height. DrawBezier(Pen, Point, Point, Point, Point) Draws a Bézier spline defined by four Point structures. DrawBezier(Pen, PointF, PointF, PointF, PointF) Draws a Bézier spline defined by four PointF structures. DrawBezier(Pen, Single, Single, Single, Single, Single, Draws a Bézier spline defined by four ordered pairs of coordinates that represent points. Single, Single, Single) DrawBeziers(Pen, Point[]) Draws a series of Bézier splines from an array of Point structures. DrawBeziers(Pen, PointF[]) Draws a series of Bézier splines from an array of PointF structures. DrawClosedCurve(Pen, Point[]) Draws a closed cardinal spline defined by an array of Point structures. DrawClosedCurve(Pen, PointF[]) Draws a closed cardinal spline defined by an array of PointF structures. DrawClosedCurve(Pen, Point[], Single, FillMode) Draws a closed cardinal spline defined by an array of Point structures using a specified tension. DrawClosedCurve(Pen, PointF[], Single, FillMode) Draws a closed cardinal spline defined by an array of PointF structures using a specified tension. DrawCurve(Pen, Point[]) Draws a cardinal spline through a specified array of Point structures. DrawCurve(Pen, PointF[]) Draws a cardinal spline through a specified array of PointF structures. DrawCurve(Pen, Point[], Single) Draws a cardinal spline through a specified array of Point structures using a specified tension.
  • 10. DrawCurve(Pen, PointF[], Single) DrawCurve(Pen, PointF[], Int32, Int32) Draws a cardinal spline through a specified array of PointF structures using a specified tension. Draws a cardinal spline through a specified array of PointF structures. The drawing begins offset from the beginning of the array. DrawCurve(Pen, Point[], Int32, Int32, Single) Draws a cardinal spline through a specified array of Point structures using a specified tension. DrawCurve(Pen, PointF[], Int32, Int32, Single) Draws a cardinal spline through a specified array of PointF structures using a specified tension. The drawing begins offset from the beginning of the array. DrawEllipse(Pen, Rectangle) Draws an ellipse specified by a bounding Rectangle structure. DrawEllipse(Pen, RectangleF) DrawEllipse(Pen, Int32, Int32, Int32, Int32) Draws an ellipse defined by a bounding RectangleF. Draws an ellipse defined by a bounding rectangle specified by coordinates for the upper-left corner of the rectangle, a height, and a width. DrawEllipse(Pen, Single, Single, Single, Single) Draws an ellipse defined by a bounding rectangle specified by a pair of coordinates, a height, and a width. DrawIcon(Icon, Rectangle) Draws the image represented by the specified Icon within the area specified by aRectangle structure. DrawIcon(Icon, Int32, Int32) DrawIconUnstretched DrawImage(Image, Point) DrawImage(Image, Point[]) Draws the image represented by the specified Icon at the specified coordinates. Draws the image represented by the specified Icon without scaling the image. Draws the specified Image, using its original physical size, at the specified location. Draws the specified Image at the specified location and with the specified shape
  • 12. System::Drawing • Graphics Class : – Can’t be inherited • Inheritance Hierarchy : – System::Object System::MarshalByRefObject System.Drawing::Graphics
  • 13. Drawing::Point • What will happen now? private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { button1->Location = 30,120; }
  • 15. Drawing::Point • What will happen now? private: System::Void button1_Click(System::Object^ System::EventArgs^ e) { Drawing::Point P; P.X = 2; P.Y = 23; button1->Location = P; } sender,
  • 17. Changing the size of the form at run time So, what should we do?
  • 18. Drawing::Size • Can we do this? Form’s size? private: System::Void button1_Click_1(System::Object^ System::EventArgs^ e) { Drawing::Size S; S.Height = 200; S.Width = 300; this->Size = S; } Yep! sender,
  • 19. Drawing::Size • Can we do this? private: System::Void button1_Click_1(System::Object^ System::EventArgs^ e) { Drawing::Size ^S; S->Height = 200; S->Width = 300; this->Size = S; } sender, Compile error Error 1 error C2664: 'void System::Windows::Forms::Control::Size::set(System::Drawing::Size)' : cannot convert parameter 1 from 'System::Drawing::Size ^' to 'System::Drawing::Size' c:userszgtrdocumentsvisual studio 2008projectsdotnet4dotnet4Form1.h 129 dotNet4
  • 21. Drawing::Size • Do this: private: System::Void button1_Click_1(System::Object^ sender, System::EventArgs^ e) { this->Size = Drawing::Size(200,300); } • Or Add Drawing in using
  • 24. System::Drawing::Pen private: System::Void button1_Click_5(System::Object^ sender, System::EventArgs^ e) { System::Drawing::Pen ^ MyPen = gcnew Pen(Color::Red); }
  • 27. Let’s draw a line!
  • 28. Graphics.DrawLine() Method private: System::Void button1_Click_5(System::Object^ System::EventArgs^ e) { System::Drawing::Graphics::DrawLine( } sender,
  • 30. System::Drawing::Pen private: System::Void button1_Click_5(System::Object^ sender, System::EventArgs^ e) { System::Drawing::Pen ^ MyPen = gcnew Pen(Color::Red); Drawing::Graphics::DrawLine( MyPen, 2, 3, 4,5 ); }
  • 31. Graphics.DrawLine Method • • • • public: void DrawLine(Pen*, Point, Point); public: void DrawLine(Pen*, PointF, PointF); public: void DrawLine(Pen*, int, int, int, int); public: void DrawLine(Pen*, float, float, float, float);
  • 34. System::Drawing • What will happen now? private: System::Void button1_Click_5(System::Object^ sender, System::EventArgs^ e) { System::Drawing::Pen ^ MyPen = gcnew Pen(Color::Red); Drawing::Graphics::DrawLine( MyPen, 2, 3, 4,5 ); } Compiler error ..
  • 36. System::Drawing • What will happen now? private: System::Void button1_Click_5(System::Object^ sender, System::EventArgs^ e) { System::Drawing::Pen ^ MyPen = gcnew Pen(Color::Red); Drawing::Graphics ^MyGraphics; MyGraphics->DrawLine( MyPen, 2, 3, 4,5 ); } No compiler error but Runtime error when clicking button1
  • 38. System::Drawing • What will happen now? private: System::Void button1_Click_5(System::Object^ sender, System::EventArgs^ e) { System::Drawing::Pen ^ MyPen = gcnew Pen(Color::Red); Drawing::Graphics ^MyGraphics; MyGraphics = pictureBox1->CreateGraphics(); MyGraphics->DrawLine( MyPen, 2, 3, 50,105 ); } A line will be drawn!
  • 40. System::Drawing • Can we do this? private: System::Void button1_Click_5(System::Object^ sender, System::EventArgs^ e) { Drawing::Graphics ^MyGraphics; MyGraphics = pictureBox1->CreateGraphics(); MyGraphics->DrawLine(System::Drawing::Pen(Color::Red),2,3,50,105); } Compiler error
  • 42. System::Drawing • Can we do this? private: System::Void button1_Click_5(System::Object^ System::EventArgs^ e) { System::Drawing::Pen MyPen(); MyPen.Color = Color::Red; Drawing::Graphics ^MyGraphics; MyGraphics = pictureBox1->CreateGraphics(); MyGraphics->DrawLine(MyPen, 2, 3, 50,105 ); } Compiler error sender,
  • 44. System::Drawing • Can we do this? private: System::Void button1_Click_5(System::Object^ System::EventArgs^ e) { System::Drawing::Pen MyPen(Color::Red ); Drawing::Graphics ^MyGraphics; MyGraphics = pictureBox1->CreateGraphics(); MyGraphics->DrawLine(MyPen, 2, 3, 50,105 ); } Compiler error sender,
  • 46. System::Drawing • Can we do this? private: System::Void button1_Click_5(System::Object^ System::EventArgs^ e) { System::Drawing::Pen ^MyPen(Color::Red); Drawing::Graphics ^MyGraphics; MyGraphics = pictureBox1->CreateGraphics(); MyGraphics->DrawLine(MyPen, 2, 3, 50,105 ); } Compiler error! sender,
  • 48. System::Drawing • Can we do this? private: System::Void button1_Click_5(System::Object^ System::EventArgs^ e) { System::Drawing::Pen ^MyPen = gcnew Pen; Drawing::Graphics ^MyGraphics; MyGraphics = pictureBox1->CreateGraphics(); MyGraphics->DrawLine(MyPen, 2, 3, 50,105 ); } Compiler error sender,
  • 50. System::Drawing • Can we do this? private: System::Void button1_Click_5(System::Object^ sender, System::EventArgs^ e) { System::Drawing::Color ^MyColor = gcnew Color; MyColor = Drawing::Color::Red; System::Drawing::Pen ^MyPen = gcnew Pen(*MyColor); Drawing::Graphics ^MyGraphics; MyGraphics = pictureBox1->CreateGraphics(); MyGraphics->DrawLine(MyPen, 2, 3, 50,105 ); } Working!
  • 51. System::Drawing • Can we do this? private: System::Void button1_Click_5(System::Object^ sender, System::EventArgs^ e) { System::Drawing::Color ^MyColor = gcnew Color; // 1 MyColor = Drawing::Color::Red; // 2 System::Drawing::Pen ^MyPen = gcnew Pen(MyColor); // 3 Drawing::Graphics ^MyGraphics; MyGraphics = pictureBox1->CreateGraphics(); MyGraphics->DrawLine(MyPen, 2, 3, 50,105 ); } Compiler error in // 3
  • 52. System::Drawing • Can we do this? private: System::Void button1_Click_5(System::Object^ sender, System::EventArgs^ e) { System::Drawing::Color MyColor = gcnew Color; // 1 MyColor = Drawing::Color::Red; // 2 System::Drawing::Pen ^MyPen = gcnew Pen(*MyColor); // 3 Drawing::Graphics ^MyGraphics; MyGraphics = pictureBox1->CreateGraphics(); MyGraphics->DrawLine(MyPen, 2, 3, 50,105 ); } Compiler error in // 1 . ^
  • 53. System::Drawing • Can we do this? private: System::Void button1_Click_5(System::Object^ sender, System::EventArgs^ e) { System::Drawing::Color ^MyColor = gcnew Color; // 1 MyColor = Red; // 2 System::Drawing::Pen ^MyPen = gcnew Pen(*MyColor); // 3 Drawing::Graphics ^MyGraphics; MyGraphics = pictureBox1->CreateGraphics(); MyGraphics->DrawLine(MyPen, 2, 3, 50,105 ); } Compiler error in // 2 un-declared Red
  • 54. System::Drawing • But remember we can just do this private: System::Void button1_Click_5(System::Object^ sender, System::EventArgs^ e) { System::Drawing::Pen ^ MyPen = gcnew Pen(Color::Red); Drawing::Graphics ^MyGraphics; MyGraphics = pictureBox1->CreateGraphics(); MyGraphics->DrawLine( MyPen, 2, 3, 50,105 ); }
  • 55. System::Drawing • Another way! private: System::Void button1_Click_5(System::Object^ sender, System::EventArgs^ e) { System::Drawing::Pen ^ MyPen = gcnew Pen(Color::Red); Drawing::Graphics ^MyGraphics; MyGraphics = pictureBox1->CreateGraphics(); Drawing::Point ^P1 = gcnew Point(50,60); Drawing::Point ^P2 = gcnew Point(150,160); MyGraphics->DrawLine( MyPen, *P1, *P2 ); } What will happen?
  • 57. System::Drawing • Another way! private: System::Void button1_Click_5(System::Object^ sender, System::EventArgs^ e) { System::Drawing::Pen ^ MyPen = gcnew Pen(Color::Red); Drawing::Graphics ^MyGraphics; MyGraphics = pictureBox1->CreateGraphics(); Drawing::Point P1 = gcnew Point(50,60); Drawing::Point P2 = gcnew Point(150,160); MyGraphics->DrawLine( MyPen, *P1, *P2 ); } What will happen? Compiler error
  • 58. System::Drawing • Another way! private: System::Void button1_Click_5(System::Object^ sender, System::EventArgs^ e) { System::Drawing::Pen ^ MyPen = gcnew Pen(Color::Red); Drawing::Graphics ^MyGraphics; MyGraphics = pictureBox1->CreateGraphics(); Drawing::Point P1 = gcnew Point(50,60); Drawing::Point P2 = gcnew Point(150,160); MyGraphics->DrawLine( MyPen, P1, P2 ); } What will happen? Compiler error
  • 59. System::Drawing • Can we do this? private: System::Void button1_Click_5(System::Object^ sender, System::EventArgs^ e) { System::Drawing::Pen ^ MyPen = gcnew Pen(Color::Red); Drawing::Graphics ^MyGraphics; MyGraphics = pictureBox1->CreateGraphics(); Drawing::Point P1(50,60); Drawing::Point P2(150,160); MyGraphics->DrawLine( MyPen, P1, P2 ); } Works!
  • 60. System::Drawing • Sth wrong? private: System::Void button1_Click_5(System::Object^ sender, System::EventArgs^ e) { System::Drawing::Pen ^ MyPen = gcnew Pen(Color::Red); Drawing::Graphics ^MyGraphics; MyGraphics = pictureBox1->CreateGraphics(); Drawing::Point P1; P1.X = 50; P1.Y = 60; Drawing::Point P2; P2.X = 150; P2.Y = 160; MyGraphics->DrawLine( MyPen, P1, P2 ); } Works!
  • 61. System::Drawing • What will happen now? private: System::Void button1_Click_5(System::Object^ sender, System::EventArgs^ e) { System::Drawing::Pen ^ MyPen = gcnew Pen(Color::Red); Drawing::Graphics ^MyGraphics; MyGraphics = pictureBox1->CreateGraphics(); Drawing::Point P1, P2; P1.X = 50; P1.Y = 60; P2.X = 150; P2.Y = 160; MyGraphics->DrawLine( MyPen, P1, P2 ); P1.X = 50; P1.Y = 60; P2.X = 510; P2.Y = 610; MyGraphics->DrawLine( MyPen, P1, P2 ); }
  • 62. System::Drawing • What’s missing? Next Lesson we’ll find out!
  • 63. Mouse! private: System::Void panel1_MouseClick(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) { System::Drawing::Point P(0,0); MyGraphics->DrawEllipse(MyPen,e->X,e->Y,10,10); MyGraphics->FillEllipse(MyBrush,e->X,e->Y,10,10); }
  • 64. That’s it for today!