Title | Draw text filled with random colored circles in Visual Basic 6 |
Description | This example shows how to draw text filled with random colored circles in Visual Basic 6. |
Keywords | random, random circles, fonts, circle filled text, VB 6, Visual Basic 6 |
Categories | Graphics, Graphics, Graphics |
|
Private Sub ShapePicture()
Const TEXT1 = "VB Helper"
Dim new_font As Long
Dim old_font As Long
Dim hRgn As Long
Dim i As Integer
Dim clr As OLE_COLOR
Dim X As Single
Dim Y As Single
Dim radius As Single
' Prepare the PictureBox.
ScaleMode = vbPixels
Picture1.AutoRedraw = True
Picture1.ScaleMode = vbPixels
Picture1.BorderStyle = vbBSNone
Picture1.BackColor = vbBlue
Picture1.ForeColor = vbBlack
Picture1.DrawWidth = 1
' Make a big font.
new_font = CustomFont(250, 65, 0, 0, _
FW_BOLD, False, False, False, _
"Times New Roman")
old_font = SelectObject(Picture1.hdc, new_font)
' Make the region.
BeginPath Picture1.hdc
Picture1.CurrentX = (ScaleWidth - _
Picture1.TextWidth(TEXT1)) / 2
Picture1.CurrentY = -40
Picture1.Print TEXT1
EndPath Picture1.hdc
hRgn = PathToRegion(Picture1.hdc)
' Constrain the PictureBox to the region.
SetWindowRgn Picture1.hWnd, hRgn, False
' Restore the original font.
SelectObject hdc, old_font
' Free font resources (important!)
DeleteObject new_font
' Draw random circles on the PictureBox.
Const min_radius As Integer = 10
Const max_radius As Integer = 100
Picture1.FillStyle = vbFSSolid
Randomize
For i = 1 To 200
clr = QBColor(Int(Rnd * 16))
X = Int(Rnd * Picture1.ScaleWidth)
Y = Int(Rnd * Picture1.ScaleHeight)
radius = Int(min_radius + Rnd * (max_radius - _
min_radius))
Picture1.FillColor = clr
Picture1.Circle (X, Y), radius, clr
Debug.Print X, Y, radius, clr '@
Next i
End Sub
|