0
我想繪製一個選擇矩形圍繞我已標記在目標上的「鏡頭」。當它在「鏡頭」的「範圍」內時,我試圖讓它啓動,但它似乎隨機出現。下面是我想要的圖像(當鼠標懸停在它上面時,圍繞鏡頭的紅色選擇矩形)以及我的代碼。在鼠標移動事件上的選擇框
Dim r As Rectangle
Dim shotList As New List(Of Point)
Dim scaleList As New List(Of Point)
Dim ShotCount As New List(Of Point)
Dim shotListBounds As New List(Of Rectangle)
Private Sub DrawShotHover(g As Graphics, location As Point, ByVal radius As Integer)
Dim pn As New Pen(Brushes.Red, 2)
Dim dashValues As Single() = {2, 1, 2, 1}
pn.DashPattern = dashValues
g.DrawRectangle(pn, New Rectangle(location.X - radius, location.Y - radius, radius * 2, radius * 2))
End Sub
Private Sub mPictureBox_MouseClick(sender As Object, e As MouseEventArgs) Handles mPictureBox.MouseClick
If e.Button = MouseButtons.Left Then
If shotFlag = True Then
Dim shot As New Point(e.X, e.Y)
shotList.Add(shot)
r = New Rectangle(e.X, e.Y, e.X + cboCaliber.EditValue/pLineDist()/2, e.Y + cboCaliber.EditValue/pLineDist()/2)
shotListBounds.Add(r)
shotDist = ShotDistance(shot)
mPictureBox.Invalidate()
End If
End Sub
Private Sub mPictureBox_Paint(sender As Object, e As PaintEventArgs) Handles mPictureBox.Paint
If LineScaleVal > 0 Then
'SELECTION RECT
If shotHoverSel = True Then
DrawShotHover(e.Graphics, r.Location, cboCaliber.EditValue/pLineDist()/2)
End If
'Point of Aim FLAG
Dim _poa As New POA(e.Graphics, New Point(_poaX, _poaY), cboCaliber.EditValue/pLineDist()/2)
'SHOT FLAG
For Each b As Point In shotList
Dim _Bullet As New Bullet(e.Graphics, b, cboCaliber.EditValue/pLineDist()/2, n)
Next
End Sub
Private Sub mPictureBox_MouseMove(sender As Object, e As MouseEventArgs) Handles mPictureBox.MouseMove
If shotListBounds.Count > 0 Then
For Each r As Rectangle In shotListBounds
Dim rad As Decimal = cboCaliber.EditValue/pLineDist()
If e.X >= r.X AndAlso e.X <= r.X + rad AndAlso e.Y >= r.Y AndAlso e.Y <= r.Y + rad Then
shotHoverSel = True
selShot = r.Location
End If
Next
End If
End Sub
Private Sub mPictureBox_MouseEnter(sender As Object, e As EventArgs) Handles mPictureBox.MouseEnter
If shotHoverSel = True Then
mPictureBox.Invalidate()
End If
End Sub
Private Sub mPictureBox_MouseLeave(sender As Object, e As EventArgs) Handles mPictureBox.MouseLeave
If shotHoverSel = False Then
mPictureBox.Invalidate()
End If
End Sub
謝謝。我會試試看。 –
我相信當你輸入一個控件時,鼠標輸入事件會被觸發。我正在「輸入」繪製的矩形(GDI +)的座標。 –
所以我嘗試了mouseenter/mouseleave事件無濟於事。該矩形只會突出顯示最後一次點擊的照片,不過鼠標移動事件會在鼠標移過鏡頭時觸發。矩形不會畫,但... –