SlideShare una empresa de Scribd logo
1 de 64
Descargar para leer sin conexión
C++.NET
Windows Forms Course
L08- GDI Part 1

Mohammad Shaker
mohammadshakergtr.wordpress.com
C++.NET Windows Forms Course
@ZGTRShaker
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
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
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);
}
Let’s draw a line!
Graphics.DrawLine() Method
private: System::Void button1_Click_5(System::Object^
System::EventArgs^ e)
{
System::Drawing::Graphics::DrawLine(
}

sender,
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);
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 ..
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
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
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,
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,
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,
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,
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!

Más contenido relacionado

La actualidad más candente

La actualidad más candente (19)

The Ring programming language version 1.5.3 book - Part 48 of 184
The Ring programming language version 1.5.3 book - Part 48 of 184The Ring programming language version 1.5.3 book - Part 48 of 184
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.3 book - Part 5 of 88The Ring programming language version 1.3 book - Part 5 of 88
The Ring programming language version 1.3 book - Part 5 of 88
 
The Ring programming language version 1.6 book - Part 32 of 189
The Ring programming language version 1.6 book - Part 32 of 189The Ring programming language version 1.6 book - Part 32 of 189
The Ring programming language version 1.6 book - Part 32 of 189
 
Gui programming
Gui programmingGui programming
Gui programming
 
37c
37c37c
37c
 
The Ring programming language version 1.5.3 book - Part 30 of 184
The Ring programming language version 1.5.3 book - Part 30 of 184The Ring programming language version 1.5.3 book - Part 30 of 184
The Ring programming language version 1.5.3 book - Part 30 of 184
 
2 BytesC++ course_2014_c9_ pointers and dynamic arrays
2 BytesC++ course_2014_c9_ pointers and dynamic arrays 2 BytesC++ course_2014_c9_ pointers and dynamic arrays
2 BytesC++ course_2014_c9_ pointers and dynamic arrays
 
My favorite slides
My favorite slidesMy favorite slides
My favorite slides
 
PART 6: FROM GEO INTO YOUR REPORT
PART 6: FROM GEO INTO YOUR REPORTPART 6: FROM GEO INTO YOUR REPORT
PART 6: FROM GEO INTO YOUR REPORT
 
Presentation1 computer shaan
Presentation1 computer shaanPresentation1 computer shaan
Presentation1 computer shaan
 
Cc code cards
Cc code cardsCc code cards
Cc code cards
 
Csphtp1 07
Csphtp1 07Csphtp1 07
Csphtp1 07
 
Yin Yangs of Software Development
Yin Yangs of Software DevelopmentYin Yangs of Software Development
Yin Yangs of Software Development
 
Python GUI Programming
Python GUI ProgrammingPython GUI Programming
Python GUI Programming
 
R-Shiny Cheat sheet
R-Shiny Cheat sheetR-Shiny Cheat sheet
R-Shiny Cheat sheet
 
PART 5: RASTER DATA
PART 5: RASTER DATAPART 5: RASTER DATA
PART 5: RASTER DATA
 
PYTHON - EXTRA Chapter GUI - MAULIK BORSANIYA
PYTHON - EXTRA Chapter GUI - MAULIK BORSANIYAPYTHON - EXTRA Chapter GUI - MAULIK BORSANIYA
PYTHON - EXTRA Chapter GUI - MAULIK BORSANIYA
 
03 Geographic scripting in uDig - halfway between user and developer
03 Geographic scripting in uDig - halfway between user and developer03 Geographic scripting in uDig - halfway between user and developer
03 Geographic scripting in uDig - halfway between user and developer
 
OpenVX 1.0 Reference Guide
OpenVX 1.0 Reference GuideOpenVX 1.0 Reference Guide
OpenVX 1.0 Reference Guide
 

Similar a C++ Windows Forms L08 - GDI P1

Java applet handouts
Java applet handoutsJava applet handouts
Java applet handouts
iamkim
 
On the tomcat drive in folder cosc210 you will find file named Paint.docx
On the tomcat drive in folder cosc210 you will find file named Paint.docxOn the tomcat drive in folder cosc210 you will find file named Paint.docx
On the tomcat drive in folder cosc210 you will find file named Paint.docx
dunhamadell
 
XNA L04–Primitives, IndexBuffer and VertexBuffer
XNA L04–Primitives, IndexBuffer and VertexBufferXNA L04–Primitives, IndexBuffer and VertexBuffer
XNA L04–Primitives, IndexBuffer and VertexBuffer
Mohammad Shaker
 
XNA L09–2D Graphics and Particle Engines
XNA L09–2D Graphics and Particle EnginesXNA L09–2D Graphics and Particle Engines
XNA L09–2D Graphics and Particle Engines
Mohammad Shaker
 
asmt7~$sc_210_-_assignment_7_fall_15.docasmt7cosc_210_-_as.docx
asmt7~$sc_210_-_assignment_7_fall_15.docasmt7cosc_210_-_as.docxasmt7~$sc_210_-_assignment_7_fall_15.docasmt7cosc_210_-_as.docx
asmt7~$sc_210_-_assignment_7_fall_15.docasmt7cosc_210_-_as.docx
fredharris32
 

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

C++ Windows Forms L09 - GDI P2
C++ Windows Forms L09 - GDI P2C++ Windows Forms L09 - GDI P2
C++ Windows Forms L09 - GDI P2
 
Chapter 13
Chapter 13Chapter 13
Chapter 13
 
Java applet handouts
Java applet handoutsJava applet handouts
Java applet handouts
 
On the tomcat drive in folder cosc210 you will find file named Paint.docx
On the tomcat drive in folder cosc210 you will find file named Paint.docxOn the tomcat drive in folder cosc210 you will find file named Paint.docx
On the tomcat drive in folder cosc210 you will find file named Paint.docx
 
Intake 37 6
Intake 37 6Intake 37 6
Intake 37 6
 
Intake 38 6
Intake 38 6Intake 38 6
Intake 38 6
 
Delphi L06 GDI Drawing
Delphi L06 GDI DrawingDelphi L06 GDI Drawing
Delphi L06 GDI Drawing
 
Cg lab cse-v (1) (1)
Cg lab cse-v (1) (1)Cg lab cse-v (1) (1)
Cg lab cse-v (1) (1)
 
XNA L04–Primitives, IndexBuffer and VertexBuffer
XNA L04–Primitives, IndexBuffer and VertexBufferXNA L04–Primitives, IndexBuffer and VertexBuffer
XNA L04–Primitives, IndexBuffer and VertexBuffer
 
XNA L09–2D Graphics and Particle Engines
XNA L09–2D Graphics and Particle EnginesXNA L09–2D Graphics and Particle Engines
XNA L09–2D Graphics and Particle Engines
 
Basic_Introduction_to_AUTOCAD.ppt
Basic_Introduction_to_AUTOCAD.pptBasic_Introduction_to_AUTOCAD.ppt
Basic_Introduction_to_AUTOCAD.ppt
 
AutoCAD-ppt.pptx
AutoCAD-ppt.pptxAutoCAD-ppt.pptx
AutoCAD-ppt.pptx
 
AutoCAD-ppt.pptx
AutoCAD-ppt.pptxAutoCAD-ppt.pptx
AutoCAD-ppt.pptx
 
AutoCAD-ppt.pptx
AutoCAD-ppt.pptxAutoCAD-ppt.pptx
AutoCAD-ppt.pptx
 
mech AutoCAD ppt.pptx
mech AutoCAD ppt.pptxmech AutoCAD ppt.pptx
mech AutoCAD ppt.pptx
 
GeoGebra 10
GeoGebra 10GeoGebra 10
GeoGebra 10
 
asmt7~$sc_210_-_assignment_7_fall_15.docasmt7cosc_210_-_as.docx
asmt7~$sc_210_-_assignment_7_fall_15.docasmt7cosc_210_-_as.docxasmt7~$sc_210_-_assignment_7_fall_15.docasmt7cosc_210_-_as.docx
asmt7~$sc_210_-_assignment_7_fall_15.docasmt7cosc_210_-_as.docx
 
Scmad Chapter06
Scmad Chapter06Scmad Chapter06
Scmad Chapter06
 
Eg5 n
Eg5 nEg5 n
Eg5 n
 
autocad.ppt
autocad.pptautocad.ppt
autocad.ppt
 

Más de Mohammad Shaker

Más de Mohammad Shaker (20)

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

Último

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Último (20)

Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 

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
  • 2.
  • 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
  • 20.
  • 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
  • 22.
  • 24. System::Drawing::Pen private: System::Void button1_Click_5(System::Object^ sender, System::EventArgs^ e) { System::Drawing::Pen ^ MyPen = gcnew Pen(Color::Red); }
  • 25.
  • 26.
  • 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,
  • 29.
  • 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);
  • 32.
  • 33.
  • 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 ..
  • 35.
  • 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
  • 37.
  • 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
  • 41.
  • 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,
  • 43.
  • 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,
  • 45.
  • 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,
  • 47.
  • 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,
  • 49.
  • 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!