我想在pb1
(图片框)中绘制椭圆,但椭圆的数量取决于查询将给出的内容。通常,它超过1.我已经有一个代码,但它只绘制一个椭圆。
我想使用数组,但我不知道如何。任何帮助/协助将不胜感激。谢谢
Sub getdots()
Try
Call MyConnection()
Sql = "select l.lot_no, l.lot_x, l.lot_y FROM lot_details AS l, area as a, type as t where l.type_no=t.type_no and t.AREA_NO=a.AREA_NO and a.AREA_NO=@Anum AND l.LOT_STATE='available'"
Dim cmd As New MySqlCommand(Sql, Con)
With cmd
.CommandText = Sql
.Connection = Con
.Parameters.AddWithValue("@Anum", frmvacantlots.cboareano.Text)
.ExecuteNonQuery()
End With
Dim reader As MySqlDataReader
reader = cmd.ExecuteReader
If reader.Read Then
Try
x = reader.GetString(1)
y = reader.GetString(2)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
Con.Close()
End Sub
Private Sub pb1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles pb1.Paint
e.Graphics.FillEllipse(Brushes.Red, x - 5, y - 5, 10, 10)
getdots()
End Sub
答案 0 :(得分:0)
创建一个列表来存储所有值:
Private points As New List(Of Point)
阅读查询中的所有要点:
While reader.Read
Try
x = reader.GetInt32(1)
y = reader.GetInt32(2)
points.Add(New Point(x, y))
Catch ex As Exception
MsgBox(ex.Message)
End Try
End While
对于 points 中的每个值,绘制就像您已经为一个值绘制的那样:
Private Sub pb1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles pb1.Paint
points.ForEach(Sub(p) e.Graphics.FillEllipse(Brushes.Red, p.X - 5, p.Y - 5, 10, 10))
getdots()
End Sub