Essential Structures [Chapter-3]

Slides:



Advertisements
Similar presentations
Graphics You draw on a Graphics object The Graphics object cannot directly be created by your code, instead one is generated when the method paintComponent.
Advertisements

User Interface Programming in C#: Graphics
Graphics and Multimedia. Outline Introduction Graphics Contexts and Graphics Objects Color Control.
Abstract Data Types and Encapsulation Concepts
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,
Differences between C# and C++ Dr. Catherine Stringfellow Dr. Stewart Carpenter.
1 Interface Types & Polymorphism & introduction to graphics programming in Java.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
Lecture 5 What is object-oriented programming OOP techniques How Windows Forms applications rely on OOP.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 26 – CheckWriter Application Introducing Graphics.
C# Programming Lecture 4 “GDI+” PGL01/CSP/2006.
Graphics and Multimedia Part #2
Graphics Concepts CS 2302, Fall /3/20142 Drawing Paths.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved CheckWriter Application Introducing Graphics and Printing.
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 7 Structured Data and Classes.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Introduction to Android (Part.
Chapter 10 Defining Classes. The Internal Structure of Classes and Objects Object – collection of data and operations, in which the data can be accessed.
(C) 2010 Pearson Education, Inc. All rights reserved.  Class Graphics (from package java.awt) provides various methods for drawing text and shapes onto.
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.
1 9/6/05CS360 Windows Programming CS360 Windows Programming.
Graphics and Java2D Chapter Java Coordinate System Origin is in _____________ corner –Behind title bar of window X values increase to the ________.
Principles of programming languages 10: Object oriented languages Isao Sasano Department of Information Science and Engineering.
Windows Programming C# Software Development. Overview  DLLs / PInvoke  DirectX .NET Component Library  Custom Controls  Event Model (in C++)  GUI.
Session 7 More Implications of Inheritance & Chapter 5: Ball World Example.
GDI +. Graphics class's methods System.Drawing Graphics Objects.
1 Sections 5.1 – 5.2 Digital Image Processing Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Introduction To GDI GDI Definition : It is a interface present in windows which provide function and related structures that an application can use to.
Arrays Chapter 7.
Printing Petzold, Chapter 21
A structured walkthrough
Principles of programming languages 10: Object oriented languages
Topic: Classes and Objects
User-Written Functions
Jim Fawcett CSE681 – SW Modeling & Analysis Fall 2014
Static data members Constructors and Destructors
Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes
Module 5: Common Type System
Chapter 5 Classes.
Programming Windows with C# Chapter23 Metafiles
Graphics and Multimedia
Computing with C# and the .NET Framework
Structs.
Java Programming: Guided Learning with Early Objects
Lesson One: The Beginning Chapter 1: Pixels Learning Processing Daniel Shiffman Presentation by Donald W. Smith Graphics from
Chapter 13: Advanced GUIs and Graphics
Basic Graphics Drawing Shapes 1.
Chapter 14 JavaFX Basics Dr. Clincy - Lecture.
Lecture 23 Polymorphism Richard Gesick.
CS313D: Advanced Programming Language
Introduction to Classes
Chapter 3 Introduction to Classes, Objects Methods and Strings
Topics Introduction to File Input and Output
CASE Tools Graphical User Interface Programming Using C#
Outline Writing Classes Copyright © 2012 Pearson Education, Inc.
Formatting a Workbook Part 1
Dr. Bhargavi Dept of CS CHRIST
Classes and Objects.
Review Session Biggest discrepancy questions
Repetition and Multiple Forms
Object Oriented Programming in java
Introducing JavaScript
Topics Introduction to File Input and Output
Chapter 12 Graphics in Windows and the Web
Review for Midterm 3.
Advanced GUIs and Graphics
Chapter 5 Classes.
Lecture Set 9 Arrays, Collections, and Repetition
Presentation transcript:

Essential Structures [Chapter-3] Course : CSE-791 Advanced Windows Programming Instructor : Dr. James Fawcett Semester : Summer 2002 Presented By : Vivekananthan Murugesan & Minu Puranik

Topics Classes and Structures Point [Two Dimensional Coordinate Points] Size [Two-Dimensional Sizes in terms of Width & Height] Rectangle Color Pens and Brushes Paint Procedures String Measurement

Classes & Structures C++ - Structure: All methods & fields are public by default - Class: All methods & fields are private by default C# - Structure: Value Type - Class: Reference Type - In both the types all methods, fields, events & properties are private by default

Value Type Vs Reference Type Question Value Type Reference Type Allocation Stack [Even though created using new – in case of struct] Heap Representation Local Copies Pointers to Memory Allocated Base Type Must derive from System.ValueType Any other type. [Except: System.ValueType & Sealed] Support Inheritance NO [Always Sealed] YES [if NOT sealed] Parameter Passing By Value [copy] By Reference Constructor Support YES. But Default Constructors are reserved. YES. [Of Course!] Existence Deleted when it falls out of the defined Scope Until Garbage Collected Example int, float, bool, any struct Form, any class

Value Type Vs Reference Type CODE EXAMPLE int a = 5 int b = a; a = 10; What is current value of b? b = 5 Form form1 = new Form(); Form form2 = form1; form2.Text = “CSE 791”; What is current value of form1.Text ? “CSE 791”

Point Point is a Number Pair (X , Y) - X : horizontal coordinate - Y : vertical coordinate - Generally represents a Point in a 2D Coordinate System - Thus, X & Y can have positive and negative values +y +x -x (0, 0) -y

Point […Continued] Point Constructor Type Example Point() Point tempPt = new Point(); //[X=0, Y=0] Point(int x, int y) Point tempPt = new Point(5, 10); // [X=5, Y=10] Point(int xypacked) Point tempPt = new Point(0x01000010); // [X=16, Y=256] Point(Size size) Point tempPt = new Point(new Size(5, 10)); // [X=5, Y=10] Special One [Using Static Field] Point tempPt =Point.Empty; // [X=0, Y=0]

Point […Continued] Point Creation Point tempPt; // WRONG!!! Point tempPt = new Point(); // YES! Point Properties Type Property Accessibility Example int X Get/Set int x = tempPt.X; //[Get] tempPt.X = 5; //[Set] Y int y = tempPt.Y; //[Get] tempPt.Y = 10; //[Set] bool IsEmpty Get bool flag = tempPt.IsEmpty; //[Get]

Point Public Interface Methods Point […Continued] Point Public Interface Methods Method Functionality Type GetType() Returns a Type object which fully describes object currently referenced [In Short: RTTI] int GetHashCode() Returns an integer which identifies a specific object instance string ToString() Returns the string representation of Object Output Format: {X=0, Y=0} Usage: Console.Write(tempPt.ToString()); bool Equals(Point) Compares two Points [Both X & Y are compared separately] Usage: bool isSame = tempPt1.Equals(tempPt2); Usage: Bool isSame = tempPt1 == tempPt2; Void Offset() Adds given offset to the Point Usage: tempPt.Offset(5,10); //tempPt.X+=5; tempPt.Y+=10;

Size Size is also a Number Pair (Width, Height) - Similar to Point, but has Width & Height instead of X & Y - Width & Height can have negative values. [Mainly used for computations purpose]

Size […Continued] Size Constructor Type Example Size() Size tempSz = new Size(); //[Width=0, Height=0] Size(int width, int height) Size tempSz = new Size(5, 10); // [Width=5, Height=10] Size(Point point) Size tempSz = new Size(new Point(5,10));

Size Creation Size tempSz; // WRONG!!! Size Properties Size tempSz = new Size(); // YES! Size Properties Type Property Accessibility Example int Weight Get/Set int w = tempSz.Width; //[Get] tempSz.Width = 5; //[Set] Height int h = tempSz.Height; //[Get] tempSz.Height = 10; //[Set] bool IsEmpty Get bool flag = tempSz.IsEmpty; //[Get]

Point & Size Construction Casting Operations Point tempPt = new Point(new Size(5, 10)); // [X=5, Y=10] Size tempSz = new Size(new Point(5,10)); // [Width=5, Height=10] Casting tempPt = (Point)tempSz; tempSz = (Size)tempPt; Operations tempSz3 = tempSz1 + tempSz2; tempSz3 = tempSz1 – tempSz2; tempSz1 += tempSz2; tempSz1 -= tempSz2; tempPt2 = tempPt1 + tempSz; tempPt2 = tempPt1 – tempSz; tempPt1 += tempSz; tempPt1 -= tempSz;

PointF and SizeF Floating Point Representations of Point and Size PointF: Similar to Point except X & Y are float values SizeF: Similar to Size except Width & Height are float values General Syntax: - tempPtF.X = 5.5; //Error - tempPtF.Y = 6.5; //Error - tempPtF.X = (float)5.5; // OR tempPtF.X = 5.5f; - tempPtF.Y = (float)6.5; // OR tempPtF.Y = 6.5f;

PointF and SizeF […Continued] Constructor Comparison Point PointF Size SizeF () (x , y) (Size) (SizeF) (Point) (PointF) (xyPacked)

PointF and SizeF […Continued] Casting To  From Point PointF Size SizeF YES NO

PointF and SizeF […Continued] Point Static Methods Name of Method Functionality Point Round(PointF ptF) Rounds X & Y to nearest positive integer. Point Truncate(PointF ptF) Strips the fractional part and rounds towards next lowest integer. Point Ceiling(PointF ptF) Rounds towards next highest integer.

PointF and SizeF […Continued] Size Static Methods Name of Method Functionality Size Round(SizeF ptF) Rounds Width & Height to nearest positive integer. Size Truncate(SizeF ptF) Strips the fractional part and rounds towards next lowest integer. Size Ceiling(SizeF ptF) Rounds towards next highest integer. SizeF Instance Methods Name of Method Functionality PointF ToPointF() Converts SizeF to PointF. Size ToSize() Equivalent to Truncate().

Rectangle “Rectangle” structure defines a rectangle as a combination of a Point and a Size Point refers to the location of the upper left corner of the rectangle and Size is the Width and Height of this Rectangle. Size should be Non-Negative. [No specific Restriction] Constructors Rectangle(Point pt, Size size) Rectangle(int x, int y, int width, int height)

RectangeF Constructors RectangleF is similar to Rectangle except that the data types associated with RectangleF are float, PointF and SizeF rather than int, Point and size. Constructors RectangleF(PointF ptf, SizeF sizef) RectangleF(float x, float y, float width, float height)

Rectangle & RectangleF Rectangle Static Methods Rectangle Round(RectangleF rectF) Rectangle Truncate(RectangleF rectF) Rectangle Ceiling(RectangleF rectF) Rectangle/RectangleF ToString Method Output Format: {X=0, Y=0, Width=0, Height=0} Note: RectangleF is similar to Rectangle except that the data types associated with RectangleF are float, PointF and SizeF rather than int, Point and size. Hence following slides refer to Rectangle which are also applicable to RectangleF.

Rectangle […Continued] Rectangle Properties Type Property Accessibility Point Location Get/Set Size int X Y Width Height Left Get Int Top Right Bottom Bool IsEmpty

Rectangle […Continued] Comparing Two Rectangles Equality Operator [==] Inequality Operator [!=] Equals Method Creating Rectanlges [Old Way] static Rectangle FromLTRB(int xLeft, int yTop, int xRight, int yBottom

Rectangle […Continued] Offset and Inflate Methods void Offset(int x, int y) void Offset(Point pt) void Inflate(int x, int y) static Rectangle Inflate(Rectangle rect, int x, int y) rect.Offset(x,y) is equivalent to: rect.X+=x; rect.Y+=y rect.Inflate(x,y) is equivalent to: rect.X-=x5; rect.Y-=y; rect.Width +=2*x; rect.Height +=2*y;

Rectangle […Continued] More Rectangle Methods static Rectangle Union(Rectangle rect1, Rectangle rect2) static Rectangle Intersect(Rectangle rect1, Rectangle rect2) void Intersect(Rectangle rect) bool Contains(Point) bool Contains(int x, int y) bool Contains(Rectangle rect) bool IntersectsWith(Rectangle rect)

Form Properties/Events - Form class has 14 Properties. [11 inherited from Control] Form(Control) Properties (selection) Type Property Accessibility Comments Point Location Get/Set Location relative to Screen Size Size of Full Form Rectangle Bounds Equals Rectangle(Location, Size) int Width Equals Size.Width Height Equals Size.Height Left Equals Location.X Top Equals Location.Y Right Get Equals Location.X + Size.Width Bottom Equals Location.Y + Size.Height

Form Properties/Events DON’T DO - Size.Width =2; //Accessing Property of Property Form Properties (selection) Type Property Accessibility Comments Point DesktopLocation Get/Set Location relative to Screen, taking windows taskbar into account Rectangle DesktopBounds Size of Full Form taking windows taskbar into account

Form Properties/Events Form(Control) Properties (selection) - Client Area Excludes: Caption Bar, Border, Menu, ScrollBar Type Property Accessibility Comments Size ClientSize Get/Set Size of ClientArea Rectangle ClientRectangle Get No Additional Information! X=0; Y=0; But useful for passing as parameter to Rectangle parameter. See: FormSize Demo

Form Properties/Events Control Events (Selection) Control Invalidate Methods Event Method Delegate Argument Move OnMove EventHandler EventArgs Resize OnResize void Invalidate() void Invalidate(Rectangle rect) void Invalidate(bool IncludeChildren) void Invalidate(Rectangle rect, bool IncludeChildren) void Invalidate(Region regn) void Invalidate(Region regn, bool IncludeChildrren)

Form Properties/Events Invalidate() - Informs the Windows that client are is no longer valid and to be repainted. - causes a call to OnPaint - OnPaint call doesn’t occur right away - all pending requests will be served first - To Update the client area immediately follow the invalidate call with a call to Control Object’s Update method. void Update();

Color Structure Color in Windows Forms is based on ARGB(a;pha-red-green-blue) model alpha channel determines the transparency of the color. It ranges from 0 for transparent to 0xFF for opaque. Construction: Color color = new Color(); //creates a transparent black color //only default constructor is supported

Color Structure Static Color Properties - Provide 140 Colors [HTML Standard] to choose from. - 141st property, named Transparent, represents a transparent color Type Property Accessibility Color AliceBlue Get AntiqueWhite … YellowGreen Transparent

Color Structure Color.FromArgb Static Methods - To create create colors based on red, green, blue and alpha components, you can use the following Color.FromArgb static methods. Color Color.FromArgb(int r, int g, int b) Color Color.FromArgb(int a, int r, int g, int b) Color Color.FromArgb(int a, Color color) Color Color.FromArgb(int argbPacked)

Pens and Brushes Pen Object is used for drawing lines or curves Brush Object is used for drawing filled areas and text Pens and Brushes themselves are specified using Color, but other characteristics are often involved as well. Constructing Pen 1. Pen mypen = new Pen(new Color()); 2. Pen mypen = new Pen(Color.Red) 3. Pen mypen = Pens.Red //Pens has 141 static properties More Descriptions about Pen on chapter 17!

Pens and Brushes Brush: - Brush class itself is abstract, which means you can’t create instance of it - Brush is parent class for 5 other classes. SolidBrush, HatchBrush, TextureBrush, LinearGradientBrush and PathGradientBrush. Brush Construction: 1. Brush mybrush = new SolidBrush(new Color()); 2. Brush mybrush = new SolidBrush(Color.Red); 3. Brush mybrush =Brushes.Red //Brushes has 141 static properties More Descriptions about Brushes on chapter 17!

System Colors Also called “User-Preference Colors” Colors set by the users for the Windows Environment using Display Properties Windows maintains 29 colors for the user interface out of which 26 are available in the Windows Forms Framework. One can obtain these colors from SystemColors class, which consists of 26 read-only properties, each of which returns a Color Object. Type Property Accessibility Comments Color ActiveBorder Get Border of Active Window ActiveCaption Caption Bar of Active Window … ControlText Text Color of Controls Desktop Windows Desktop Color WindowText Window Text

Pens and Brushes Creating Pens and Brushes using SystemColors: - Pen mypen = new Pen(SystemColor.Desktop); - Brush mybrush = new SolidBrush(SystemColor.Desktop); SystemPens: - has 15 static read only properties that return object of type Pen Type Property Accessibility Pen ActiveCaptionText Get Control … WindowText

Pens and Brushes SystemBrushes: - has 21 static read only properties that return object of type Brush Type Property Accessibility Brush ActiveBorder Get ActiveCaption … WindowText

Pens & Brushes More Ways to Create: Pen mypen = SystemPens.FromSystemColor(SystemColor.ActiveBorder); Brush mybrush = SystemBrushes.FromSystemColor(SystemColor.MenuText); Known Colors: KnownColor is an Enumeration that encompasses all the color names and all the system colors

Form Examples RandomClear Example: RandomClearResizeRedraw Example: - Clears the Form with different colors selected at random. - Clear is restricted to the region that’s newly invalid. thus entire form is not repainted. RandomClearResizeRedraw Example: - 1 way for complete Clear: override OnResize and Put a invalidate call. - Another way is set the ResizeRedraw property to true.

StringFormat Used to Change the default text alignment Properties: StringAlignment Enumeration: Type Property Accessibility Comments StringAlignment Alignment Get/Set Horizontal alignment Color LineAlignment Vertical Alignment Member Value Description Near Usually left or top Center 1 Always Center Far 2 Usually right or bottom More Descriptions about StringFormat on chapter 9!

Form Examples FourCorners Example - Using StringFormat to display Text HelloCenteredAlignment Example HelloCenteredMeasured Example - Using SizeF sizeText = grfx.MeasueString(str, font); More Descriptions about MeasueString on chapter 9!

Form Examples HelloCenteredRectangle Example HuckleberryFinn Example - Using void DrawString(string str, Font f, Brush b, Rectangle rect, Stringformat strfmt) HuckleberryFinn Example void DrawString(string str, Font f, Brush b, Rectangle rect)

Reference Programming Microsoft Windows with C# - Charles Petzold C# and the .Net Platform - Andrew Troelsen