专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > VB Dotnet

怎么绘制三角形

发布时间:2011-06-23 15:57:10 文章来源:www.iduyao.cn 采编人员:星星草
如何绘制三角形?
要做一个指针仪表控件,指针采用三角形,以中心点旋转,请问如何绘制三角形并旋转???

------解决方案--------------------
给你一个例子:
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
paintClock(Me.ClientRectangle)
End Sub
Friend Sub paintClock(ByVal rect As Rectangle)
If (Not MyBase.IsDisposed AndAlso MyBase.Visible) Then
Dim graphics1 As BufferedGraphics = BufferedGraphicsManager.Current.Allocate(MyBase.CreateGraphics, rect)
If (Not graphics1.Graphics Is Nothing) Then
graphics1.Graphics.Clear(Me.BackColor)
Me.drawClock(graphics1.Graphics, MyBase.ClientRectangle)
End If
graphics1.Render()
graphics1.Dispose()
End If
End Sub

Private Sub drawClock(ByVal g As Graphics, ByVal rectangle As Rectangle)
Dim brush1 As New SolidBrush(Color.SteelBlue)
Dim brush2 As New SolidBrush(Color.SkyBlue)
Dim brush3 As New SolidBrush(Color.Teal)
Dim brush4 As New SolidBrush(Color.Teal)
Dim brush5 As New SolidBrush(Color.Black)
Dim pen1 As New Pen(brush1, 2.0!)
Dim pen2 As New Pen(brush2, 1.5!)
Dim pen3 As New Pen(brush3, 0.2!)
Dim pen4 As New Pen(brush4, 0.2!)
Dim pen5 As New Pen(brush5, 1.0!)
Dim point1 As New Point((MyBase.ClientRectangle.Left + (MyBase.ClientRectangle.Width / 2)), (MyBase.ClientRectangle.Top + (MyBase.ClientRectangle.Height / 2)))
Dim num1 As Integer = 1
Do While (num1 <= 60)
If ((num1 Mod 5) = 0) Then
g.DrawEllipse(pen1, CSng((point1.X + CInt((Math.Cos(((Math.PI / 180 * num1) * 6)) * 60)))), CSng((point1.Y + CInt((Math.Sin(((Math.PI / 180 * num1) * 6)) * 60)))), 2.0!, 2.0!)
Else
g.DrawEllipse(pen2, CSng((point1.X + CInt((Math.Cos(((Math.PI / 180 * num1) * 6)) * 60)))), CSng((point1.Y + CInt((Math.Sin(((Math.PI / 180 * num1) * 6)) * 60)))), 1.5!, 1.5!)
End If
num1 += 1
Loop
Dim point2 As New Point((point1.X + CInt((Math.Cos((Math.PI / 180 * (((DateTime.Now.Hour - 3) * 30) + ((DateTime.Now.Minute / 12) * 6)))) * 40))), (point1.Y + CInt((Math.Sin((Math.PI / 180 * (((DateTime.Now.Hour - 3) * 30) + ((DateTime.Now.Minute / 12) * 6)))) * 40))))
Dim point3 As New Point((point1.X + CInt((Math.Cos((Math.PI / 180 * (((DateTime.Now.Hour + 3) * 30) + ((DateTime.Now.Minute / 12) * 6)))) * 7))), (point1.Y + CInt((Math.Sin((Math.PI / 180 * (((DateTime.Now.Hour + 3) * 30) + ((DateTime.Now.Minute / 12) * 6)))) * 7))))
Dim point4 As New Point((point1.X + CInt((Math.Cos((Math.PI / 180 * ((DateTime.Now.Hour * 30) + ((DateTime.Now.Minute / 12) * 6)))) * -5))), (point1.Y + CInt((Math.Sin((Math.PI / 180 * ((DateTime.Now.Hour * 30) + ((DateTime.Now.Minute / 12) * 6)))) * -5))))
Dim point5 As New Point((point1.X + CInt((Math.Cos((Math.PI / 180 * ((DateTime.Now.Hour * 30) + ((DateTime.Now.Minute / 12) * 6)))) * 5))), (point1.Y + CInt((Math.Sin((Math.PI / 180 * ((DateTime.Now.Hour * 30) + ((DateTime.Now.Minute / 12) * 6)))) * 5))))
Dim pointArray1 As Point() = New Point() {point2, point4, point3, point5}
g.FillPolygon(brush1, pointArray1)
Dim point6 As New Point((point1.X + CInt((Math.Cos(((Math.PI / 180 * (DateTime.Now.Minute - 15)) * 6)) * 48))), (point1.Y + CInt((Math.Sin(((Math.PI / 180 * (DateTime.Now.Minute - 15)) * 6)) * 48))))
Dim point7 As New Point((point1.X + CInt((Math.Cos(((Math.PI / 180 * (DateTime.Now.Minute + 15)) * 6)) * 9))), (point1.Y + CInt((Math.Sin(((Math.PI / 180 * (DateTime.Now.Minute + 15)) * 6)) * 9))))
Dim point8 As New Point((point1.X + CInt((Math.Cos(((Math.PI / 180 * DateTime.Now.Minute) * 6)) * -4))), (point1.Y + CInt((Math.Sin(((Math.PI / 180 * DateTime.Now.Minute) * 6)) * -4))))
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: