Click here to Skip to main content
15,899,754 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,

I need to draw a hexgon in vb.net. It has draw stack order (like one coloumn)as well as row type. for example "L" shape.

please help me.

by
Gopi A.
Posted

Using a picturebox control is pointless. If you want to have a control you can position and handle it's paint event, you may as well use a panel.

I found this with google:

Change count to 6 and draw a line...

Code:
VB
Private Sub Form_Load()
  Dim px As Double, py As Double, i%, cnt%, r1 As Double, r As Double
  px = ScaleWidth / 2 - Text1(0).Width / 2
  py = ScaleHeight / 2 - Text1(0).Height / 2
  r = 1365    ' radius
  cnt = 12    ' number of images
  Text1(0).Move px, py
  Text1(0).Visible = False
  For i = 1 To cnt
    If Not i = 0 Then Load Text1(i)
    With Text1(i)
       r1 = 360 / cnt * (i) * 3.1428571 / 180
      .Move px + r * Sin(r1), py - r * Cos(r1)
      .Text = i
      .Visible = True
    End With
Next i
End Sub


This draws numbers on a clock face

In other words, change cnt from 12 to 6, and draw lines between the points it creates to draw a hexagon.
 
Share this answer
 
v2
You could use Graphics to draw lines in a picturebox or any other control. The disadvantage of this is that when u minimize and restore the window, you'll lose the image.

I'd recommend using a picturebox control, and servicing it's 'Paint' event. Something like this :

VB
Private Sub picBox_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles picBox.Paint

Public gPen As New Pen(Color.Green, 3)

e.Graphics.DrawLine(gPen , x1, y1, x2, y2)
e.Graphics.DrawLine(gPen , x1, y1, x2, y2)

'you can use a combination of these lines to draw a hexagon
'or decorate it further using rectangles, ellipses etc.
'type out e. graphics.draw and check out the intellisense
'to view your options

End sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900