CST238 Week 5 Questions / Concerns? Announcements – HW#1 due (Project ideas) – Check-off Take...

Post on 11-Jan-2016

219 views 4 download

Tags:

transcript

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 presentations start next Monday (#1&#2)

• Test#1• Take Home Lab#5

Recap• Timer– Tick event

• DateTime– Get current date / time

• MDI applications– Main form– Child form (set its MDIparent to main form)

GUI Blooper Presentations• Limit your presentation to 30 minutes. Both

team members need to present. • Summary the key points in the chapter.• Show examples given in the book.• When possible, show actual GUI examples

from applications/websites that you have used.

Drawing• You need the Graphics class from

System.Drawing namespace.• Two ways to get a Graphics object– Create a new that’s associated with the form or

control– Grab the Graphics object in the Paint event’s

PaintEventArgs

Drawing• There are 2 types of draw:– Immediate Draw• Not updated after form resize, covered or uncovered.

– Redraw• Updated each time a form is updated. • This is done through Paint event. • This event can be triggered using Invalidate

Drawing• Get Graphics object:– Create a Graphics object for the form or control

Graphics g = this.CreateGraphics();Graphics g = pictureBox1.CreateGraphics();

– void DrawingForm_Paint(object sender, PaintEventArgs e)

{ Graphics g = e.Graphics;

Drawing• Classes that you might need:– Color– Brushes– Pens

• Read Chapter 5, 6 & 7 in the Chris Sells book as reference on different shapes to draw and different pens and brushes to use.

Grid System XY

(X, Y)

Drawing• Drawing procedure:

1. Obtain a Graphics object.2. Obtain a tool to use on the Graphics object.

- pen, brushes, fonts, etc.

3. Call methods on the Graphics object to draw your picture.

4. Trigger redraw is necessary by Invalidate the form or control

Methods of the Graphics class• Draw methods– DrawLine, DrawArc, DrawImage, DrawEllipse,

DrawRectangle• Fill methods– FillEllipse, FillPolygon, FillRectangle

Drawing• Drawing directly on the form– Know the size of the form

• Drawing on one of the controls– Panel– PictureBox– Use the Width and Height for the control

Form: Size

Form’s ClientRectangle

(284, 262)

(300, 300)

Take Home Lab #5• Draw a static picture. – Try different styles of pens and brushes.– Try different shapes, lines, images, text. – Add some immediately drawn shapes via a button, but

keep the main picture updated. – Be creative but it doesn’t have to be very complex or fancy.