我已經完成了大量搜索並找不到所需的幫助。在圖片框中的鼠標位置放置圓圈
我需要能夠放置一些直徑爲140像素的圓形圖片在圖片框中的圖片的某些部分。在圖像上單擊鼠標時應出現圓圈。我需要將圓的中心放置在鼠標點擊位置。用戶還應該能夠將圓圈放置在圖像上時將其拖動到其他位置。
任何人都可以給我一些指導如何做到這一點?
在此先感謝!
我已經完成了大量搜索並找不到所需的幫助。在圖片框中的鼠標位置放置圓圈
我需要能夠放置一些直徑爲140像素的圓形圖片在圖片框中的圖片的某些部分。在圖像上單擊鼠標時應出現圓圈。我需要將圓的中心放置在鼠標點擊位置。用戶還應該能夠將圓圈放置在圖像上時將其拖動到其他位置。
任何人都可以給我一些指導如何做到這一點?
在此先感謝!
這可能會啓動你。借鑑PictureBox.Click
Private Sub PictureBox1_Click(sender As System.Object, e As MouseEventArgs) Handles PictureBox1.Click
Dim myBrush As New System.Drawing.SolidBrush(System.Drawing.Color.Red)
Dim formGraphics As System.Drawing.Graphics
formGraphics = sender.CreateGraphics()
formGraphics.FillEllipse(myBrush, New Rectangle(e.X/2, e.Y/2, 70 , 70))
myBrush.Dispose()
formGraphics.Dispose()
End Sub
編輯 一個簡單的紅色圓圈看起來exaclty像你正在尋找 http://www.dreamincode.net/forums/topic/59049-simple-drawing-selection-shape-or-rubberband-shape/
* ...你是否期待有人爲你寫的方法??他正在期待其他人... –
不,我沒有期待有人寫我的方法。如果您注意到,我只會在我的問題中要求提供指導。 – user3310131
感謝您的幫助pt000。這個鏈接非常有用! – user3310131
我的解決辦法:`
Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
'start creating circle when the mouse is clicked
PictureBox1.Refresh() 'erases previous rectangle
Xstart = e.X
Ystart = e.Y
bRB = True
End Sub
Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
'drag the circle over the seclected area
If bRB Then
PictureBox1.Refresh() 'erases previous rectangle
Select Case e.X
Case Is < 0
RBRectangle.X = 0
' RBRectangle.Width = Xstart
RBRectangle.Width = 140
Case 0 To Xstart
RBRectangle.X = e.X
'RBRectangle.Width = Xstart - e.X
RBRectangle.Width = 140
Case Xstart To PBWidth
RBRectangle.X = Xstart
'RBRectangle.Width = e.X - Xstart
RBRectangle.Width = 140
Case Is > PBWidth
RBRectangle.X = Xstart
'RBRectangle.Width = PBWidth - Xstart
RBRectangle.Width = 140
End Select
Select Case e.Y
Case Is < 0
RBRectangle.Y = 0
'RBRectangle.Height = Ystart
RBRectangle.Height = 140
Case 0 To Ystart
RBRectangle.Y = e.Y
'RBRectangle.Height = Ystart - e.Y
RBRectangle.Height = 140
Case Ystart To PBHeight
RBRectangle.Y = Ystart
'RBRectangle.Height = e.Y - Ystart
RBRectangle.Height = 140
Case Is > PBHeight
RBRectangle.Y = Ystart
'RBRectangle.Height = PBHeight - Ystart
RBRectangle.Height = 140
End Select
PictureBox1.CreateGraphics.DrawEllipse(RBPen, RBRectangle)
End If
End Sub
Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
'show the area in the rectangle as a new image
Dim CroppedBm As Bitmap
If bRB Then
bRB = False
CroppedBm = New Bitmap(RBRectangle.Width, _
RBRectangle.Height)
End If
End Sub
試試這個:
Dim g As Graphics
Dim md As Boolean
Private Sub Form1_Load() Handles MyBase.Load
g = PictureBox1.CreateGraphics
End Sub
Private Sub PictureBox1_MouseClick(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseClick
PictureBox1.Refresh()
g.DrawEllipse(Pens.Red, New Rectangle(e.X - 35, e.Y - 35, 70, 70))
End Sub
Private Sub PictureBox1_MouseDown(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseDown
md = True
End Sub
Private Sub PictureBox1_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseMove
If md Then
PictureBox1.Refresh()
g.DrawEllipse(Pens.Red, New Rectangle(e.X - 35, e.Y - 35, 70, 70))
End If
End Sub
Private Sub PictureBox1_MouseUp(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseUp
md = False
End Sub
你有沒有你已經有的代碼的任何例子,或者你是否期待有人爲你寫這個方法? – TylerDurden
你可能想要開始與System.Drawing.Graphics :) –