Advertisement
Guest User

Untitled

a guest
Oct 20th, 2014
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.15 KB | None | 0 0
  1.  
  2. 'Option Strict On
  3. 'Option Explicit On
  4.  
  5. Public Class Main
  6.  
  7. Public picWidth As Integer
  8. Public picHeight As Integer
  9. Public picCenter As Boolean
  10.  
  11. Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  12.  
  13. 'Initial Width
  14. picWidth = 2000
  15. picHeight = 2000
  16.  
  17. 'PictureBox Conforming
  18. PictureBox1.Width = picWidth
  19. PictureBox1.Height = picHeight
  20.  
  21. 'MenuStrip Above All
  22. MenuStrip1.BringToFront()
  23.  
  24. End Sub
  25.  
  26. Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
  27.  
  28. End Sub
  29.  
  30. Private Sub PictureBox_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles PictureBox1.MouseMove
  31.  
  32. Static mousePosX As Single, mousePosY As Single
  33.  
  34. If e.Button = 0 Then
  35.  
  36. mousePosX = e.X
  37. mousePosY = e.Y
  38.  
  39. Else
  40.  
  41. If e.Button = Windows.Forms.MouseButtons.Left Then
  42.  
  43. PictureBox1.Left = PictureBox1.Left + (e.X - mousePosX)
  44. PictureBox1.Top = PictureBox1.Top + (e.Y - mousePosY)
  45.  
  46. ToolStripStatusLabel2.Text = "X: " & e.X.ToString & "Y: " & e.Y.ToString
  47.  
  48. ElseIf e.Button = Windows.Forms.MouseButtons.Right Then
  49.  
  50. ' Draw a hexagonal lattice in the center of the form
  51. Dim pic As Bitmap = New Bitmap(picWidth, picHeight)
  52. Dim halfSide As Integer = pic.Size.Width \ 64
  53. Dim side As Integer = halfSide * 2 ' The length of a side of a hexagon.
  54. Dim oneAndAHalfSide As Integer = halfSide * 3
  55. Dim twoAndAHalfSide As Integer = halfSide * 5
  56. Dim halfHeight As Integer = CInt(side * Math.Sqrt(3)) \ 2
  57. ' Draw on the image, not the form...
  58. Using g As Graphics = Graphics.FromImage(pic)
  59. ' There are various options to smooth the lines.
  60. g.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
  61. ' Draw the lines in a black pen, width 2.
  62. Using p As New Pen(Color.Black, 2)
  63. For y As Integer = 0 To pic.Size.Width - 1 Step halfHeight * 2
  64. For x As Integer = side \ 2 To pic.Size.Width - 1 Step side * 3
  65. Dim pt1 As New Point(x, y)
  66. Dim pt2 As New Point(x + side, y)
  67. Dim pt3 As New Point(x - halfSide, y + halfHeight)
  68. Dim pt4 As New Point(x - halfSide, y - halfHeight)
  69. Dim pt5 As New Point(x + oneAndAHalfSide, y + halfHeight)
  70. Dim pt6 As New Point(x + oneAndAHalfSide, y - halfHeight)
  71. Dim pt7 As New Point(x + twoAndAHalfSide, y - halfHeight)
  72. g.DrawLine(p, pt1, pt2)
  73. g.DrawLine(p, pt1, pt3)
  74. g.DrawLine(p, pt1, pt4)
  75. g.DrawLine(p, pt2, pt5)
  76. g.DrawLine(p, pt2, pt6)
  77. g.DrawLine(p, pt6, pt7)
  78. Next
  79. Next
  80. End Using
  81. End Using
  82.  
  83. 'Load Hexagonal Lattice
  84. PictureBox1.BackgroundImage = pic
  85.  
  86. End If
  87.  
  88. End If
  89.  
  90. End Sub
  91.  
  92. Private Sub PictureBox_MouseWheel(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseWheel
  93. If e.Delta <> 0 Then
  94. If e.Delta <= 0 Then
  95. If PictureBox1.Width < 500 Then Exit Sub 'minimum 500?
  96. Else
  97. If PictureBox1.Width > 2000 Then Exit Sub 'maximum 2000?
  98. End If
  99.  
  100. PictureBox1.Width += CInt(PictureBox1.Width * e.Delta / 1000)
  101. PictureBox1.Height += CInt(PictureBox1.Height * e.Delta / 1000)
  102.  
  103. End If
  104.  
  105. End Sub
  106.  
  107. Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click
  108.  
  109. Me.Close()
  110.  
  111. End Sub
  112.  
  113. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement