View Single Post
Old 01-03-2010, 05:28 PM
boops boops's Avatar
boops boops boops boops is offline
Join Date: Dec 2006
Location: Holland and France
Posts: 146

Here's a class you can add to your project to provide hexagonal picture boxes. You can set its properties in code or in the designer like a normal picture box. To add it in the designer, first build your project with the new class. The HexPictureBox tool will appear in the toolbox with a cogwheel icon. It will look like a normal picture box on the form but it will be hexagonal when you run the program. Code:
Public Class HexPictureBox Inherits PictureBox Protected Overrides Sub OnSizeChanged(ByVal e As System.EventArgs) SetRegion() MyBase.OnSizeChanged(e) End Sub Private Sub SetRegion() Dim p(5) As Point Dim v As Integer = CInt(Me.Width / 2 * Math.Sin(30 * Math.PI / 180)) p(0) = New Point(Me.Width \ 2, 0) p(1) = New Point(Me.Width, v) p(2) = New Point(Me.Width, Me.Height - v) p(3) = New Point(Me.Width \ 2, Me.Height) p(4) = New Point(0, Me.Height - v) p(5) = New Point(0, v) Using gp As New Drawing2D.GraphicsPath gp.AddPolygon(p) Me.Region = New Region(gp) End Using End Sub End Class
Attached Images
File Type: png hexPictureBox.png (237.2 KB, 37 views)

Last edited by boops boops; 01-03-2010 at 05:35 PM.
Reply With Quote