1 Graphic Device Interface (GDI). 2 Class Form A Form is a representation of any window displayed in your application. The Form class can be used to create.

Slides:



Advertisements
Similar presentations
Graphics and Multimedia Session 13 Mata kuliah: M0874 – Programming II Tahun: 2010.
Advertisements

Računarska grafika GDI+ (Graphics Device Interface Plus)
User Interface Programming in C#: Graphics
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Topics  Applets  Classes used for graphics Graphics Point Dimension.
.NET Class 4 – Windows-based Application. WinForm Application Homogeny programming model. Rich class library Classes are shared by all.NET languages.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Java Applets What is an Applet? How do you create.
Chapter 13 Graphics, Animation, Sound, and Drag-and-Drop Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 5 Java Graphics Applets.
Graphics and Multimedia. Outline Introduction Graphics Contexts and Graphics Objects Color Control.
Graphics and Multimedia. Outline Drawing Polygons and Polylines Advanced Graphics Capabilities.
Java Review Structure of a graphics program. Computer Graphics and User Interfaces Java is Object-Oriented A program uses objects to model the solution.
Syracuse University 3D Framework using GDI+.Net Carmen Vaca Ruiz Independent Study Fall 2004 Instructor: Dr. Jim Fawcett.
Računarska grafika GDI+ (Graphics Device Interface Plus)
Graphics and Multimedia. Introduction The language contains many sophisticated drawing capabilities as part of namespace System.Drawing and the other.
Graphics Images – PictureBox control Drawing graphics - Graphics object Multimedia controls PictureBox control Image property – select image Choose how.
1 Chapter 26 D&D – Graphics Outline 26.1 Introduction 26.3 Graphics Contexts and Graphics Objects 26.4 Color Control 26.5 Font Control 26.6 Drawing Lines,
Lecture Set 13 Drawing Mouse and Keyboard Events Part A - Drawing.
Windows Programming Using C#
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Java Applets What is an Applet? How do you create.
Computer Programming and Basic Software Engineering 9 Building Graphical User Interface A Brief Introduction to GDI+ S.R.G. Fraser, Pro Visual C++/CLI.
CST238 Week 5 Questions / Concerns? Announcements – HW#1 due (Project ideas) – Check-off Take Home lab#4 Recap New topics – Drawing Coming up: – GUI Bloopers.
1 Graphic Device Interface (GDI). 2 Class Form A Form is a representation of any window displayed in your application. The Form class can be used to create.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 26 – CheckWriter Application Introducing Graphics.
1 Windows Graphics. 2 Objectives You will be able to Use the Windows GDI+ to draw arbitrary figures and text on a Windows form. Add a handler for the.
Object Oriented Programming Graphics and Multimedia Dr. Mike Spann
C# Programming Lecture 4 “GDI+” PGL01/CSP/2006.
CSC 298 Windows Forms.
Graphics and Multimedia Part #2
COM148X1 Interactive Programming Lecture 6. Topics Today Generate Random Numbers Graphics Animation.
1 Scroll Bars Providing Scrollbars. 2 Objectives You will be able to: Use Windows Graphics to display tabular information on a Windows form. Add graphics.
Chapter 11 Bitmaps, Icons and Cursors. Copyright 2006 © Thomas P. Skinner2 Background Bitmaps are easy in.NET. Two kinds of graphics: 1.Vector 2.Bitmaps.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved CheckWriter Application Introducing Graphics and Printing.
Chapter2: Drawing a Window. Drawing with the GDI.
GDI+ 1. Objectives 2 GDI+ class  Create and render Graphic  Display information on the computer screen, printer 3.
J McQuillan SE204: 2004/2005: Lecture 4slide 1 The Graphics Class Used when we need to draw to the screen Two graphics classes –Graphics –Graphics2D.
McGraw-Hill © 2010 The McGraw-Hill Companies, Inc. All rights reserved. Chapter 13 Graphics, Animation, Sound and Drag-and-Drop.
Lecture 5 Graphics Erick Pranata. » Graphics Overview » About GDI+ » Getting Started.
Računarska grafika GDI+ (Graphics Device Interface Plus)
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Introduction to Android (Part.
Ray Konopka Creating Custom Microsoft.NET Framework Controls in Delphi.
Graphics and Java2D Chapter Java Coordinate System Origin is in _____________ corner –Behind title bar of window X values increase to the ________.
Graphics and Multimedia. OUTLINE Font Control Drawing Lines, Rectangles and Ovals Drawing Arcs Drawing a General Path.
Images Part 11 dbg. 2 Images The form and several controls can display a number of different types of image files in the BackgroundImage Property. These.
Windows Programming C# Software Development. Overview  DLLs / PInvoke  DirectX .NET Component Library  Custom Controls  Event Model (in C++)  GUI.
V 1.0 Programming III. Graphical possibilities Simple graphics (shapes)
1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
AWT Java AWT (Abstract Windowing Toolkit) is an API to develop GUI or window-based application in java. Java AWT components are platform-dependent i.e.
GDI +. Graphics class's methods System.Drawing Graphics Objects.
(PART II) Graphics and Multimedia. Font Control Font s  After a Font is created, its properties cannot be modified  Programmers must create a new Font.
Graphics and Multimedia 2 Lecture 8. OUTLINE Font Control Drawing Lines, Rectangles and Ovals Drawing a General Path.
(PART II) Graphics and Multimedia 11/02/1437 Lect6 (Part 2)
Essential Structures [Chapter-3]
Lines, Curves, and Area Fill
Graphics.
Graphics and Multimedia
Computer Programming I
Graphics and Multimedia
Drawing Mouse and Keyboard Events Part A - Drawing
Basic Graphics Drawing Shapes 1.
ThS. Nguyễn Hà Giang Khoa CNTT - Hutech
CASE Tools Graphical User Interface Programming Using C#
Lecture 9 GUI and Event Driven CSE /16/2019.
Repetition and Multiple Forms
Object Oriented Programming
Graphics and Multimedia
Chapter 12 Graphics in Windows and the Web
Images and Bitmaps (in C#)
CPT 450 Computer Graphics 3rd Lecture.
Lines, Curves and Area Fills
Presentation transcript:

1 Graphic Device Interface (GDI)

2 Class Form A Form is a representation of any window displayed in your application. The Form class can be used to create standard, tool, borderless, and floating windows. The events of the Form class allow you to respond to actions performed on the form. You can use the Activated event to perform operations such as updating the data displayed in the controls of the form when the form is activated. You can use a form as the starting class in your application by placing a method called Main() in the class. In the Main() method add code to create and show the form.

3 Some Event functions of Form protected override void OnClick( EventArgs e ) protected override void OnKeyDown( KeyEventArgs e) protected override void OnMouseDown( MouseEventArgs e) protected override void OnMouseEnter( MouseEventArgs e) protected override void OnMouseHove( MouseEventArgs e) protected override void OnMouseMove( MouseEventArgs e) protected override void OnMouseUp( MouseEventArgs e) protected override void OnMouseLeave( MouseEventArgs e) protected override void OnPaint( PaintEventArgs e ) protected override void OnResize(EventArgs e) Note: EventArgs is parent class of all other *** EventArgs

4 Class Point Namespace: System.Drawing Constructor Point p = new Point(int x, int y ); x y

5 Class Rectangle Constructor Rectangle r = new Rectangle( Point( x, y ), Size( w, h )); Rectangle r = new Rectangle( int x, int y, int w, int h ); x y w h

6 class Color Some static Color objects Color.Red Color.Yellow Color.Blue Color object can be obtained from RGB formation Color c1 = Color.FromArgb(200, 128, 48); We also can use 0   255 to control color  means opaque,  means transparent    means half transparent  For example: Color c2 = Color.FromArgb( , c1); Color c2 = Color.FromArgb( , 200, 128, 48);

7 Class Pen Namespace: System.Drawing Pen object draws a line of specified width and style. Constructor Pen(Color object, int width); Pen p = new (Color.Red, 3) Some Pen objects can be got from class Pens Pens.Red Pens.Yellow Pens.Blue They all have width 1

8 Class Font Constructor Font( FontFamily family, float Size, FontStyle style ); Example Font f = new Font("Arial", 36, FontStyle.Bold|FontStyle.Italic );

9 Class Brush Namespace: System.Drawing Brush object used to fill the interiors of graphical shapes such as rectangles, ellipses, pies, polygons, and paths. This is an abstract class. Use derived classes such as : SolidBrush(Color object) TextureBrush(Image object) (In Namespace: System.Drawing.Drawing2D) LinearGradientBrush(Point1, Point1, Color1, Color2) HatchBrush(HatchStyle, Color1, Color2)

10 Class Graphics Namespace: System.Drawing The Graphics class provides methods for drawing objects to the display device. A Graphics object is associated with a specific device context, which means every Form has a built- in Graphics object. The following method is wrong: Graphics g = new Graphics()

11 Some Methods of Graphics public void DrawArc(Pen, Rectangle, float angle1, float angle2); public void DrawLine(Pen, Point p1, Point p2); public void DrawLine(Pen, int x1, int y1, int x2, int y2); public void DrawRectangle(Pen, Rectangle); public void DrawRectangle(Pen, int x, int y, int w, int h); public void DrawEllipse(Pen, Rectangle); public void DrawImage(Image, Point); public void DrawString(string, Font, Brush, Point); public void FillEllipse(Brush, Rectangle); public void FillRectangle(Brush, Rectangle);

12 Operations in OnPaint() All code inside OnPaint() will be executed when the application window is showing to the screen. protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics ; Pen blackPen = new Pen(Color.Black, 3); Rectangle rect = new Rectangle( 0, 0, 200, 100); g.DrawEllipse(blackPen, rect);

13 Pen redPen = new Pen(Color.Red, 3); Point p1 = new Point(150, 150); Point p2 = new Point(500, 300); g.DrawLine(redPen, p1, p2); g.FillEllipse(new SolidBrush(Color.FromArgb (180,Color.Green)), new Rectangle(50,50, 200,200)) ; g.FillRectangle(new SolidBrush(Color.Red), 20, 20, 50, 50); g.FillRectangle(new SolidBrush(Color.FromArgb(180, Color.Yellow)), 40, 40, 50, 50); HatchBrush hb= new HatchBrush(HatchStyle.ForwardDiagonal, Color.Green, Color.FromArgb(100, Color.Yellow)); g.FillEllipse(hb, 250, 10, 100, 100); Image newImage = Image.FromFile("dog.gif"); g.DrawImage(newImage, new Point( 300, 100));

14 string drawString = "UH Sugarland"; Font drawFont = new Font("Arial", 36, FontStyle.Bold|FontStyle.Italic ); SolidBrush drawBrush = new SolidBrush(Color.Red); PointF drawPoint = new Point(50, 300); g.DrawString(drawString, drawFont, drawBrush, drawPoint); LinearGradientBrush lb = new LinearGradientBrush ( new Point(200,200), new Point(400,300), Color.Yellow, Color.Blue); g.FillRectangle(lb, 200, 200, 200, 100); }

15 Output