Visual C - PowerPoint PPT Presentation

1 / 10
About This Presentation
Title:

Visual C

Description:

Text use the DrawString method. State the text: font, brush and x,y position: ... grpObject.DrawString('string', arial, myBrush, 0, 100) ... – PowerPoint PPT presentation

Number of Views:37
Avg rating:3.0/5.0
Slides: 11
Provided by: johnal1
Category:

less

Transcript and Presenter's Notes

Title: Visual C


1
Visual C Images, Graphics and Multimedia - 1
  • Images PictureBox control
  • Drawing graphics
  • - Graphics object
  • Multimedia controls
  • PictureBox control
  • Image property select image
  • Choose how to display stretch,auto, centre,
    zoom

2
Visual C Images, Graphics and Multimedia - 2
Drawing Graphics No graphics controls (e.g.
circle or rectangle) A Graphics object is created
on a canvas e.g. a form or panel A pen or
brush object is defined Pens for lines, brush
for fill areas Graphics methods are called to
draw or paint. Text, Lines and shapes can be
drawn Origin (0,0) is top left-hand corner of
screen
3
Visual C Images, Graphics and Multimedia - 3
Example Draw Line on panel1 MouseDown
event Code (placed in forms mouseDown
event) System.Drawing.Graphics
grpObject grpObject this.panel1.CreateGraphics(
) Pen objmyPen new Pen(System.Drawing.Color.Bl
ue) grpObject.DrawLine(objmyPen, 0, 0, 100,
100) On mouse down line is drawn from 0,0 to
100,100
4
Visual C Images, Graphics and Multimedia - 4
Problem Line disappears if form is minimised
or hidden. Paint event Use paint event to redraw
graphics add code private void
panel1_Paint(object sender, PaintEventArgs e)
System.Drawing.Graphics grpObject
e.Graphics Pen objmyPen new Pen(System.Drawing.
Color.Red) grpObject.DrawLine(objmyPen, 0, 100,
100, 0) Red line drawn, click to display
blue line, minimise and display shows red line
only Note use of e.Graphics from event args to
get object
5
Visual C Images, Graphics and Multimedia - 5
To force redraw use Invalidate(
) Panel1.Invalidate() Drawing on the
form Override the onPaint event write your own
protected override void OnPaint(PaintEventArgs
e) Graphics grpObject e.Graphics Pen
objmyPen new Pen(System.Drawing.Color.Blue) grp
Object.DrawLine(objmyPen, 0, 0, 100, 100)
6
Visual C Images, Graphics and Multimedia - 6
The pen and brush objects Pen for lines, brush
for areas Pen Color - Alpha (transparency)
RGB, width and style (solid, dash, dot
etc.) objmyPen.Width 3 objmyPen.DashStyle Syst
em.Drawing.Drawing2D.DashStyle.DashDotDot objmyPe
n.Color System.Drawing.Color.FromArgb(128, 255,
0, 0) grpObject.DrawLine(objmyPen, 0, 100, 100,
0)
7
Visual C Images, Graphics and Multimedia - 7
The Brush is similar Create brush
object Properties Color and style Text use
the DrawString method. State the text font,
brush and x,y position Graphics grpObject
e.Graphics // from OnPaint override SolidBrush
myBrush new SolidBrush(Color.Red) Font arial
new Font("Arial", 12) myBrush.Color
Color.Green // change brush color grpObject.Draw
String(string, arial, myBrush, 0, 100)
8
Visual C Images, Graphics and Multimedia - 8
Other shapes arcs, pies, polylines and polygons
DrawArc( Pen p, int X, int Y, int width, int
height, int startAngle, int sweepAngle) DrawPie
( Pen p, int X, int Y, int width, int height, int
startAngle, int sweepAngle) FillPie ( Brush b,
int X, int Y, int width, int height, int
startAngle, int sweepAngle) Polyline and
Polygon connect points passed in an ArrayList
myGrpObject.FillPolygon(myBrush, arrayofPoints)
Example in notes of polygon
9
Visual C Images, Graphics and Multimedia - 9
Charts 2D or 3D graphs? No controls Draw your own
or buy in. Simple 2D chart at the Coding4Fun
site Some free controls at http//www.carlosag.n
et/Tools/WebChart/Default.aspx Well draw graphs
later with NPlot add-on
10
Visual C Images, Graphics and Multimedia - 10
Multimedia applications MediaPlayer control
Need to add to toolbox URL given for
media axWindowsMediaPlayer1.URL
_at_"c\windows\clock.avi" Can control,
e.g. axWindowsMediaPlayer1.Ctlcontrols.stop( )
Write a Comment
User Comments (0)
About PowerShow.com