Advertisement
Guest User

Graphics exercise1

a guest
Jun 15th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Public Class Form1
  2.  
  3.     Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
  4.         Dim myGraphics As Graphics = PictureBox1.CreateGraphics
  5.         Dim myPen0 As New Pen(Color.Blue, 5)
  6.         Dim myPen1 As New Pen(Color.Gray, 0.5) : Dim myPen2 As New Pen(Color.Red, 2)
  7.         Dim a, id As Integer
  8.         Dim x1, y1, angle As Single
  9.         myGraphics.Clear(Me.BackColor)
  10.         myGraphics.DrawRectangle(myPen0, x1, y1, 499, 499)
  11.         a = 150
  12.         For id = 0 To 500 Step 50
  13.             myGraphics.DrawLine(myPen1, id, 0, id, 500)
  14.             myGraphics.DrawLine(myPen1, 0, id, 500, id)
  15.         Next
  16.         myGraphics.TranslateTransform(500 / 2, 500 / 2)
  17.  
  18.         If TextBox1.Text >= 250 Then
  19.             MsgBox("The Largest Radius should be less than 500")
  20.             TextBox1.Clear()
  21.             Return
  22.         End If
  23.  
  24.  
  25.         For a = TextBox1.Text / 5 To TextBox1.Text Step TextBox1.Text / 5
  26.  
  27.  
  28.             For id = 0 To 360 Step 2
  29.                 angle = id * Math.PI / 180
  30.                 x1 = a * Math.Cos(angle) : y1 = a * Math.Sin(angle)
  31.                 myGraphics.DrawRectangle(myPen2, x1, y1, 1, 1)
  32.             Next id
  33.         Next
  34.  
  35.  
  36.         myGraphics.Dispose()
  37.     End Sub
  38.     Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
  39.         Me.AutoSize = True
  40.         PictureBox1.Top = 0 : PictureBox1.Left = 0
  41.         PictureBox1.Width = 500 : PictureBox1.Height = 500
  42.         Button1.Left = PictureBox1.Width + 50 : Button1.Top = 150
  43.         Label1.Left = PictureBox1.Width + 50 : Label1.Top = 140
  44.  
  45.     End Sub
  46. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement