CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2005
    Posts
    13

    how to draw a hexagon?

    hey there, im trying to make an application that will create a hex-map (essentially a grid map where each cell is a hexagon instead of a square).... im not really sure where to start with this, but i figured that the best place to start would be one single cell.... is hexagon an object that is supported already? ie. does the system.drawing allow for hexagons to be drawn

  2. #2
    Join Date
    Mar 2004
    Location
    33°11'18.10"N 96°45'20.28"W
    Posts
    1,808

    Re: how to draw a hexagon?

    call DrawPolygon and pass in the 6 points needed to draw your shape.
    Last edited by MadHatter; March 3rd, 2008 at 05:54 PM.

  3. #3
    Join Date
    Jan 2005
    Posts
    13

    Re: how to draw a hexagon?

    thanks for the help.... i was thinking that i would have to do that and it turns out i have to.... i was hoping for something easier, but if thats how it needs to be done, then so be it

  4. #4
    Join Date
    Mar 2004
    Location
    33°11'18.10"N 96°45'20.28"W
    Posts
    1,808

    Re: how to draw a hexagon?

    you can always create helper methods to do things like drawing a hexagon that wrap the lower level api's, and make your life a little easier.

  5. #5
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: how to draw a hexagon?

    Change count to 6 and draw a line...
    Code:
    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
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  6. #6
    Join Date
    May 2005
    Location
    Sterling Heights, MI
    Posts
    74

    Re: how to draw a hexagon?

    Why VB6 code in response to a question posted in the C# section?

  7. #7
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: how to draw a hexagon?

    MadHatter is correct about the DrawPolygon method - that's what I would have done as well. I prefer to make use of the .NET classes as much as possible, instead of API ( although they can be extremely handy ), I guess it's just a matter of opinion

    Here is a very nice example to get you started with drawing Hexagons, only issue I have with this article is the fact that it's not a CG one !

    http://www.codeproject.com/KB/cs/hexagonal_part1.aspx

    I hope my post was useful, if even a little

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured