我在vb.net的图片框中创建了一个椭圆,我希望如果我点击这个椭圆,它会打开另一个表格。图片框中包含一张地图图片,我只是简单地将椭圆放在地图上的建筑物上,我想你会想到它会告诉我有关该建筑物的信息......
注意:如果您在vb.net中有一种更简单的创建交互式地图的方式,其中有关地图的信息和图像存储在mysql数据库中..
答案 0 :(得分:3)
这是一个示例应用程序,演示如何使用该区域计算一个点是否落入椭圆内:
注意:创建一个新的WinForms应用程序并将代码粘贴到Form1.vb
:
Public Class Form1
Private ellipse_center As Point
Private A As Integer = 140
Private B As Integer = 90
Private isInsideEllipse As Boolean
Private canvasRect As Rectangle
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Me.SetStyle(ControlStyles.UserPaint, True)
Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
Me.SetStyle(ControlStyles.ResizeRedraw, True)
Me.Font = New Font(Me.Font.FontFamily, 12, FontStyle.Bold)
End Sub
Private Sub Form1_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove
isInsideEllipse = (e.Location.X - ellipse_center.X) ^ 2 / (A / 2) ^ 2 + (e.Location.Y - ellipse_center.Y) ^ 2 / (B / 2) ^ 2 <= 1
Me.Invalidate()
End Sub
Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
Dim g As Graphics = e.Graphics
Using p As New Pen(If(isInsideEllipse, Brushes.Blue, Brushes.Red), 2)
g.DrawEllipse(p, ellipse_center.X - A \ 2, ellipse_center.Y - B \ 2, A, B)
End Using
g.DrawString("Pointer is" + If(isInsideEllipse, " ", " not ") + "inside the ellipse", Me.Font, Brushes.Black, 5, 5)
End Sub
Private Sub Form1_Resize(sender As Object, e As EventArgs) Handles Me.Resize
canvasRect = Me.DisplayRectangle
canvasRect.Inflate(-1, -1)
ellipse_center = New Point(canvasRect.Width / 2, canvasRect.Height / 2)
End Sub
End Class
顺便说一下,我在这里找到了正确的公式:Check if a point is within an ellipse @ Mathematics