Title: More Graphics
1More Graphics
- CS0004
- Lecture 23
- Chapter 9.3
2Admin
- Project 5
- Due Wednesday, April 18th
- Final Exam
- Next Wednesday, April 25th
- Post study sheet and sample exam tonight
3Other Objects
- Group Box
- Groups items together
- Radio Buttons
- Select one item in a list
- Used in conjunction with Group Box
- Check Box
- Yes/No input
4Checked Property
- Checked Property used to determine if either a
radio button or check box is selected - If rdoNixon.Checked Then
- MsgBox(You voted for Nixon)
- End If
5The Timer Control
- Invisible during run time
- Triggers an event after a specified period of
time - The Interval property specifies the time period
measured in milliseconds - To begin timing, set the Enabled property to True
- To stop timing, set the Enabled property to False
- The event triggered each time Timer1.Interval
elapses is called Timer1.Tick.
6Example 3 Form
txtSeconds
7Example 3 Code
- Private Sub btnStart_Click(...) Handles
btnStart.Click - txtSeconds.Text "0" 'Reset watch
- tmrWatch.Enabled True
- End Sub
- Private Sub btnStop_Click(...) Handles
btnStop.Click - tmrWatch.Enabled False
- End Sub
- Private Sub tmrWatch_Tick(...) Handles
tmrWatch.Tick - txtSeconds.Text CStr((CDbl(txtSeconds.Text)
0.1)) - End Sub
8Pixels
- The graphics unit of measurement is called a
pixel. - A pixel is a single dot on the screen
- Each pixel has two properties
- Color
- Location ( x , y , z )
- We will only deal with x and y
9Coordinates in a Picture Box
- Each point in a picture box is identified by a
pair of coordinates, (x, y).
y pixels
(x, y)
x pixels
10Drawing
- Draw Circle/Ellipse
- gr.DrawEllipse(Pens.Red, 35, 35, 70, 70)
- Draw Solid Circle/Ellipse
- gr.FillEllipse(Brushes.Red, 35, 35, 70, 70)
- Draw Text
- gr.DrawString("World",Me.Font, Brushes.Red, 35,
50) - Draw Line
- gr.DrawLine(Pens.Blue, 50, 20, 120, 75)
- Draw Solid Rectangle
- gr.DrawRectangle(Pens.Blue, 50, 20, 70, 55)
- Draw Solid Rectangle
- gr.FillRectangle(Brushes.Blue, 50, 20, 70, 55)
11Display Text
Dim gr As Graphics picBox.CreateGraphics Dim
strVar As String "Hello" gr.DrawString(strVar,
Me.Font, Brushes.Blue, 4, 30) gr.DrawString("World
",Me.Font, Brushes.Red, 35, 50)
12Draw a Sector
The statement gr.FillPie(Brushes.Color, a - r, b
- r, _ 2 r, 2 r, startAngle,
sweepAngle) draws a solid sector of a circle with
center (a, b), radius r, and having the specified
startAngle and sweepAngle. The color of the
sector is determined by the value of Color.
13Start and Sweep Angles
14Single Data Type
Numeric variables used in Draw and Fill
statements must be of type Integer or Single. The
Single data type is similar to the Double type,
but has a smaller range (-3.41038 to
3.41038). CSng converts other data types to the
Single data type.
15Financing Public Schools Data
16Financing Public Schools Pie Chart
17Create the Pie Chart
Dim gr As Graphics picBox.CreateGraphics Dim
percent() As Single .08, .49, .43 Dim br() As
Brush Brushes.Blue, _
Brushes.Red, Brushes.Tan Dim sumOfSweepAngles As
Single 0 For i As Integer 0 To 2
gr.FillPie(br(i), 5, 5, 200, 200, _
sumOfSweepAngles, percent(i) 360)
sumOfSweepAngles percent(i) 360 Next
18Financing Public Schools Bar Chart
19Financing Public Schools Bar Chart
- Suppose the x-axis is 110 pixels below the top of
the picture box. - Let the unit for the rectangle heights be .5
pixels. - Then the top of a rectangle corresponding to the
quantity q is 110 q/2 pixels from the top of
the picture box.
20Create the Bar Chart
Dim gr As Graphics picBox.CreateGraphics Dim
quantity() As Single 33, 206, 180 'Draw
x-axis gr.DrawLine(Pens.Black, 40, 110, 210, 110)
'Draw y-axis gr.DrawLine(Pens.Black, 40, 110, 40,
0) For i As Integer 0 To 2 gr.FillRectangle(Br
ushes.Blue, _ 60 i 40, (110 quantity(i)
/ 2), _ 20, quantity(i) / 2) Next
21Animation
- Draw a circle and move it around (slowly)
- Appears like a bouncing ball
22Move Ball
The following code moves the ball along a
diagonal with each tick of the timer. Dim x As
Single 0 Dim y As Single 0 Private Sub
Timer1_Tick(...) Handles _
Timer1.Tick Dim gr As Graphics
picBox.CreateGraphics gr.FillEllipse(Brushes.Colo
r, x, y, 10,10) x 2 y 10 End Sub
23Finished!
- Material up to here is covered on test
- Post a detailed list of items tonight along with
a sample exam - Comprehensive exam
- Functions
- If statements
- Variables
24Database
- A database is a collection of data that is
grouped into a series of tables - Tables are just like two dimensional arrays
25Sample Table
26Database Terminology
- A table is a rectangular array of data.
- Each column of the table, called a field,
contains the same type of information. - Each row, called a record, contains all the
information about one entry in the database.
27Data representation
- Lets say we have city data about certain major
cities. - We also have state data about the states these
cities are located. - Represent it as two separate tables
28How data looks
Cities
States