1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
Private Sub BTTriangle_Click(sender As Object, e As EventArgs) Handles BTTriangle.Click
TextBox2.Text = " "
Dim oVal, i, som As Integer
i = 1
som = 0
oVal = TextBox1.Text
'drawing
Dim oCol, oSpace, oCount, oRow As Integer
Dim oPen As Pen
oPen = New Pen(Drawing.Color.DarkCyan, 2)
Dim oGraphics As Graphics = Me.PicBox.CreateGraphics
oGraphics.Clear(SystemColors.Control)
Dim oRect As New Rectangle
oSpace = 10
oRect.X = PicBox.Width / 2
oRect.Y = oSpace
oRect.Width = oSpace
oRect.Height = oSpace
oCol = oRect.X
oCount = 0
While som < oVal
oRow += 1
som = som + i
i = 1 + i
oRect.X = oCol
For j = 1 To i - 1
oCount += 1
If oCount > oVal Then
oPen.Color = Color.Red
End If
oGraphics.DrawEllipse(oPen, oRect)
oRect.X += oSpace * 2
Next
oRow += 1
oCol -= oSpace
oRect.Y += 20
End While
If oRow > 9 Then
oGraphics.ScaleTransform(0.5, 0.5) '<----------------- ICI ---------------------
End If
If som = oVal Then
TextBox2.Text = "triangle"
Else
TextBox2.Text = "not triangle: " & (oVal - oCount).ToString & " too little"
End If
'Debug.Print("ici")
End Sub |
Partager