W09 Graphics
W09 Graphics
Visual
Instructor: Saima Jawad
Programming
Graphics
BASICS
SYSTEM.DRAWING
PAINT EVENT
COLOR, FONT, PEN, BRUSH
LINES, RECTANGLES, ELLIPSES,
ARCS, POLYLINE AND POLYGON
Week-09 Outline
(0, 0)
+x
x-axis
A graphics context
is a drawing surface, +y
form or a panel
y-axis
Basic Graphics
4
Graphics g;
…
// get g
g.DrawLine()…
System.Drawing key
Font class
Color
FontFamily structure
Point
Graphics
Rectangle
Icon
Size
Pen
Region
Image
HatchBrush
Bitmap
LinearGradientBrush
ImageAnimator
PathGradientBrush
Brush
SolidBrush
TextureBrush
private void myForm_Paint (object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Pen pen = new Pen( Color.Blue );
g.DrawLine(pen, 0, 0, 150, 150);
}
static FromArgb Creates a color based on red, green and blue values expressed as ints
from 0 to 255. Overloaded version allows specification of alpha, red,
green and blue values.
static FromName Creates a color from a name, passed as a string.
Common Properties
A byte between 0 and 255, representing the alpha component.
R byte between 0 and 255, representing the red component.
G byte between 0 and 255, representing the green component.
Drawing an Ellipse
18
height
width
Drawing Arcs
24
270° 270°
180° 0° 180° 0°
90° 90°
Properties of an Arc
Starting angle
Arc angle
Positive and negative arc angles.
Bounding rectangle
g.DrawLines(coloredPen, pointsArray);
g.DrawPolygon(coloredPen, pointsArray);
g.FillPolygon(solidBrush, pointsArray);
} // end switch
} // end method imageComboBox_SelectedIndexChanged