当前位置:网站首页>vb.net 画曲线
vb.net 画曲线
2022-07-31 11:38:00 【laocooon】
Public Class Form1
Public Enum Type
None = 0
Line = 1
Cirle = 2
PolyLine = 3
Curve = 4
End Enum
Dim m_Type As Type = Type.None
Dim First As Point
Dim Last As Point
Dim g As Graphics
Dim listPoint As New List(Of Point)
Private Sub Initial(sender As Object, e As EventArgs) Handles Button1.Click, Button2.Click, Button3.Click, Button4.Click, MyBase.Load
m_Type = Type.None
First = Point.Empty
Last = Point.Empty
Dim c As Control = TryCast(sender, Control)
If IsNothing(c) Then Exit Sub
Select Case c.Name
Case "Button1"
m_Type = Type.Line
Case "Button2"
m_Type = Type.Cirle
Case "Button3"
m_Type = Type.PolyLine
Case "Button4"
m_Type = Type.Curve
End Select
End Sub
Private Sub Form1_MouseClick(sender As Object, e As MouseEventArgs) Handles MyBase.MouseClick
Dim pen As Pen = New Pen(Color.Red)
g = Me.CreateGraphics()
If e.Button = MouseButtons.Left Then
'分情况
Select Case m_Type
Case Type.None
Return
Case Type.Line
If First = Point.Empty Then
First = New Point(e.X, e.Y)
Else
Last = New Point(e.X, e.Y)
g.DrawLine(pen, First, Last)
Me.Initial(Nothing, e) '取消
End If
Case Type.Cirle
If First = Point.Empty Then
First = New Point(e.X, e.Y)
Else
Dim R As Integer = Math.Sqrt((First.X - e.X) * (First.X - e.X) + (First.Y - e.Y) * (First.Y - e.Y))
Dim left As New Point(First.X - R, First.Y - R)
g.DrawEllipse(pen, left.X, left.Y, 2 * R, 2 * R)
Me.Initial(Nothing, e) '取消
End If
Case Type.PolyLine
If First = Point.Empty Then
First = New Point(e.X, e.Y)
Else
Last = New Point(e.X, e.Y)
g.DrawLine(pen, First, Last)
First = Last
End If
Case Type.Curve
If First = Point.Empty Then
First = New Point(e.X, e.Y)
listPoint.Add(First)
Else
Last = New Point(e.X, e.Y)
listPoint.Add(Last)
If Type.Curve = m_Type Then
If listPoint.Count = 3 Then
g.DrawCurve(pen, listPoint.ToArray(), 0.5)
End If
End If
End If
End Select
ElseIf e.Button = MouseButtons.Right Then
Me.Initial(Nothing, e) '取消
End If
End Sub
End Class
边栏推荐
猜你喜欢
随机推荐
Life is endless, there are more questions, simple questions to learn knowledge points
MySQL模糊查询性能优化
IDEA 配置方法注释自动参数
Docker practical experience: Deploy mysql8 master-slave replication on Docker
lotus-local-net 2k v1.17.0-rc4
瑞吉外卖项目:新增菜品与菜品分页查询
deeplab实现自己遥感地质分割数据集
Different lower_case_table_names settings for server (‘1‘) and data dictionary (‘0‘) 解决方案
数据湖(十九):SQL API 读取Kafka数据实时写入Iceberg表
Summary of several defragmentation schemes for MySQL (to solve the problem of not releasing space after deleting a large amount of data)
keras自带数据集(横线生成器)
Curl 命令使用
MySQL 的 limit 分页查询及性能问题
7 days to learn Go, Go structure + Go range to learn
在 Excel 里使用 ODBC 读取 SAP BTP 平台上 CDS view 的数据
Distributed id solution
最全phpmyadmin漏洞汇总
Different lower_case_table_names settings for server ('1') and data dictionary ('0') solution
初始JDBC 编程
结构化查询语言SQL-关系数据库标准语言