怎么绘制三角形
发布时间: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))))
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。
其他相似内容:
-
关于VB.net中的验证控件
小弟正在开发一个C/S结构程序,有几个界面有较多的textbox,是关于用户数据输入的,现在想做验证,听说有验证控...
-
多表查询问题
我有三个表,一个表为基本表,一个是代码表,一个是出差表
表一 编号,姓名 ,职别
001 李三 101
...
-
DATAGRIDVIEW无法删除未提交的新行?
再DATAGRIDVIEW录入时,想删除最后自动新增的一行,提示无法删除未提交的新行
Private Sub Dat...
-
迷茫了几天,求各位高手指教一下!下面是我的代码!
<!--#include file="webconfig.asp"-->
<%
Dim SortID
SortID=Trim(FLib.SafeSql(R...
-
vb.net 断开和连接网络连接 修改代码
在vb.net中实现断开和连接网络连接的代码,我在网上找了一段代码
Option Explicit On
'首...
-
DataGridView直接导出EXCEL
如何直接读取DataGridView中的数据,并导出成Excel可以直接读取的文件
记住,我不要通过DataTable。
希...
-
求教:如何在vb.net下做一些好看的界面,整一些好看的效果,改变控件,让控件变得好看点?
有没有点例子?有没有点直接可以做控件的软件?
---...
-
在VB中,对SQL数据库进行增删改语句怎么写呢?
小弟做课程设计,遇到了一点小麻烦,卡在了这里,不知道在VB中怎么写对SQL数据库的增删改...
-
文本框中的数字精确到小数点后两位
请问如何让文本框输入数字后精确到小数点后两位,如:当输入112时,显示为112.00
------解决方案--...
-
VB.NET2008如何利用SendMessage修改按钮的Text?
为了测试 Windows API ,试图点Button用SendMessage修改该按钮的Text,竟然没成功,请教...