Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'Option Strict On
- 'Option Explicit On
- Public Class Main
- Public picWidth As Integer
- Public picHeight As Integer
- Public picCenter As Boolean
- Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- 'Initial Width
- picWidth = 2000
- picHeight = 2000
- 'PictureBox Conforming
- PictureBox1.Width = picWidth
- PictureBox1.Height = picHeight
- 'MenuStrip Above All
- MenuStrip1.BringToFront()
- End Sub
- Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
- End Sub
- Private Sub PictureBox_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles PictureBox1.MouseMove
- Static mousePosX As Single, mousePosY As Single
- If e.Button = 0 Then
- mousePosX = e.X
- mousePosY = e.Y
- Else
- If e.Button = Windows.Forms.MouseButtons.Left Then
- PictureBox1.Left = PictureBox1.Left + (e.X - mousePosX)
- PictureBox1.Top = PictureBox1.Top + (e.Y - mousePosY)
- ToolStripStatusLabel2.Text = "X: " & e.X.ToString & "Y: " & e.Y.ToString
- ElseIf e.Button = Windows.Forms.MouseButtons.Right Then
- ' Draw a hexagonal lattice in the center of the form
- Dim pic As Bitmap = New Bitmap(picWidth, picHeight)
- Dim halfSide As Integer = pic.Size.Width \ 64
- Dim side As Integer = halfSide * 2 ' The length of a side of a hexagon.
- Dim oneAndAHalfSide As Integer = halfSide * 3
- Dim twoAndAHalfSide As Integer = halfSide * 5
- Dim halfHeight As Integer = CInt(side * Math.Sqrt(3)) \ 2
- ' Draw on the image, not the form...
- Using g As Graphics = Graphics.FromImage(pic)
- ' There are various options to smooth the lines.
- g.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
- ' Draw the lines in a black pen, width 2.
- Using p As New Pen(Color.Black, 2)
- For y As Integer = 0 To pic.Size.Width - 1 Step halfHeight * 2
- For x As Integer = side \ 2 To pic.Size.Width - 1 Step side * 3
- Dim pt1 As New Point(x, y)
- Dim pt2 As New Point(x + side, y)
- Dim pt3 As New Point(x - halfSide, y + halfHeight)
- Dim pt4 As New Point(x - halfSide, y - halfHeight)
- Dim pt5 As New Point(x + oneAndAHalfSide, y + halfHeight)
- Dim pt6 As New Point(x + oneAndAHalfSide, y - halfHeight)
- Dim pt7 As New Point(x + twoAndAHalfSide, y - halfHeight)
- g.DrawLine(p, pt1, pt2)
- g.DrawLine(p, pt1, pt3)
- g.DrawLine(p, pt1, pt4)
- g.DrawLine(p, pt2, pt5)
- g.DrawLine(p, pt2, pt6)
- g.DrawLine(p, pt6, pt7)
- Next
- Next
- End Using
- End Using
- 'Load Hexagonal Lattice
- PictureBox1.BackgroundImage = pic
- End If
- End If
- End Sub
- Private Sub PictureBox_MouseWheel(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseWheel
- If e.Delta <> 0 Then
- If e.Delta <= 0 Then
- If PictureBox1.Width < 500 Then Exit Sub 'minimum 500?
- Else
- If PictureBox1.Width > 2000 Then Exit Sub 'maximum 2000?
- End If
- PictureBox1.Width += CInt(PictureBox1.Width * e.Delta / 1000)
- PictureBox1.Height += CInt(PictureBox1.Height * e.Delta / 1000)
- End If
- End Sub
- Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click
- Me.Close()
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement