在vb.net中画一个六边形 [英] draw a hexgon in vb.net

查看:121
本文介绍了在vb.net中画一个六边形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,

我需要在vb.net中绘制一个六边形.它具有绘制堆栈顺序(如一个列)以及行类型.例如"L"形.

请帮帮我.


Gopi A.

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.

推荐答案

使用图片框控件毫无意义.如果您想拥有一个控件,则可以定位和处理其绘画事件,也可以使用面板.

我在google上找到了它:

将计数更改为6并画一条线...

代码:
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:
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



这会在钟面上绘制数字

换句话说,将cnt从12更改为6,并在其创建的点之间绘制线条以绘制六边形.



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.


您可以使用Graphics在图片框或任何其他控件中绘制线条.这样做的缺点是,当您最小化并还原窗口时,您将丢失图像.

我建议使用图片框控件,并为它的绘画"事件提供服务.像这样的东西:

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 :

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


这篇关于在vb.net中画一个六边形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆