|
| 1 | +VERSION 5.00 |
| 2 | +Begin VB.Form frmBars3 |
| 3 | + Caption = "Bars3" |
| 4 | + ClientHeight = 3195 |
| 5 | + ClientLeft = 60 |
| 6 | + ClientTop = 345 |
| 7 | + ClientWidth = 4680 |
| 8 | + LinkTopic = "Form1" |
| 9 | + ScaleHeight = 3195 |
| 10 | + ScaleWidth = 4680 |
| 11 | + StartUpPosition = 3 'Windows Default |
| 12 | +End |
| 13 | +Attribute VB_Name = "frmBars3" |
| 14 | +Attribute VB_GlobalNameSpace = False |
| 15 | +Attribute VB_Creatable = False |
| 16 | +Attribute VB_PredeclaredId = True |
| 17 | +Attribute VB_Exposed = False |
| 18 | +Option Explicit |
| 19 | + |
| 20 | +Private Const NUM_VALUES = 7 |
| 21 | +Private DataValue(1 To NUM_VALUES) As Integer |
| 22 | + |
| 23 | +' Set the form's Scale properties. |
| 24 | +Private Sub SetTheScale(ByVal obj As Object, ByVal upper_left_x As Single, ByVal upper_left_y As Single, ByVal lower_right_x As Single, ByVal lower_right_y As Single) |
| 25 | + obj.ScaleLeft = upper_left_x |
| 26 | + obj.ScaleTop = upper_left_y |
| 27 | + obj.ScaleWidth = lower_right_x - upper_left_x |
| 28 | + obj.ScaleHeight = lower_right_y - upper_left_y |
| 29 | +End Sub |
| 30 | +' Create some random data. |
| 31 | +Private Sub Form_Load() |
| 32 | +Dim i As Integer |
| 33 | + |
| 34 | + Randomize |
| 35 | + For i = 1 To NUM_VALUES |
| 36 | + DataValue(i) = Rnd * 100 |
| 37 | + Next i |
| 38 | +End Sub |
| 39 | + |
| 40 | + |
| 41 | +' Draw the bar chart. |
| 42 | +Private Sub Form_Paint() |
| 43 | +Dim i As Integer |
| 44 | +Dim wid As Single |
| 45 | +Dim hgt As Single |
| 46 | + |
| 47 | + ' Define the custom coordinate system. |
| 48 | + SetTheScale Me, 0, 110, NUM_VALUES + 2, -10 |
| 49 | + |
| 50 | + ' Clear the form. |
| 51 | + Cls |
| 52 | + |
| 53 | + ' Draw the bar chart. |
| 54 | + For i = 1 To NUM_VALUES |
| 55 | + ' Pick a new fill style. |
| 56 | + FillStyle = i Mod 8 |
| 57 | + |
| 58 | + ' Draw a box with i <= X <= i + 1 and |
| 59 | + ' 0 <= Y <= Data(i). |
| 60 | + Line (i, 0)-(i + 1, DataValue(i)), , B |
| 61 | + Next i |
| 62 | + |
| 63 | + ' Draw a 5 by 5 pixel box at position |
| 64 | + ' (NUM_VALUES / 2 + 1, 50). |
| 65 | + wid = ScaleX(5, vbPixels, ScaleMode) |
| 66 | + hgt = ScaleY(5, vbPixels, ScaleMode) |
| 67 | + Line (NUM_VALUES / 2 + 1, 50)-Step(wid, hgt), vbRed, BF |
| 68 | +End Sub |
| 69 | + |
| 70 | + |
0 commit comments