Wrap-Up

Answers to Self Review Exercises

17.1

a) False. Size is a read-only property. b) True. c) True. d) True. e) False. It returns the size of the current Font in design units. f) False. The coordinate (0,0) corresponds to the upper-left corner of a GUI component on which drawing occurs. g) False. A Pen is used to draw lines, a HatchBrush fills a shape with a hatch pattern. h) False. A color is defined by its alpha, red, green and blue content. i) True. j) True.

 
17.2

a) Pen. b) LinearGradientBrush, PathGradientBrush. c) DrawLine. d) alpha, red, green, blue. e) points. f) TextureBrush. g) Windows Media Player h) GraphicsPath i) System.Drawing, System.Drawing.Drawing2D. j) FromFile.

Exercises

17.3

Write a program that draws eight concentric circles. The circles should be separated from one another by 10 pixels. Use the DrawArc method.

17.4

Write a program that draws 100 lines with random lengths, positions, thicknesses and colors.

17.5

Write a program that draws a tetrahedron (a pyramid). Use class GraphicsPath and method DrawPath.

17.6

Write a program that allows the user to draw "free-hand" images with the mouse in a PictureBox. Allow the user to change the drawing color and width of the pen. Provide a button that allows the user to clear the PictureBox.

17.7

Write a program that repeatedly flashes an image on the screen. Do this by interspersing the image with a plain background-color image.

17.8

(Eight Queens) A puzzler for chess buffs is the Eight Queens problem. Simply stated: Is it possible to place eight queens on an empty chessboard so that no queen is "attacking" any other (i.e., so that no two queens are in the same row, in the same column or along the same diagonal)?

Create a GUI that allows the user to drag-and-drop each queen on the board. Use the graphical features of Fig. 17.26. Provide eight queen images to the right of the board (Fig. 17.38) that the user can drag-and-drop on the board. When a queen is dropped on the board, its corresponding image to the right should not be visible. If a queen is in conflict with another queen when placed on the board, display a message box and remove that queen from the board.

Figure 17.38. GUI for the Eight Queens exercise.

Категории