Vb.net 将圆圈放置在图片框中的鼠标位置
我已经做了很多搜索,找不到我需要的帮助 我需要能够将一些直径为140像素的圆放在图片盒中图像的某些部分上。当鼠标单击图像时,圆圈应出现。我需要将圆圈的中心放置在鼠标单击时的位置。用户还应该能够将圆圈放置在图像上后将其拖动到其他位置 有谁能给我一些关于如何做到这一点的指导吗Vb.net 将圆圈放置在图片框中的鼠标位置,vb.net,picturebox,Vb.net,Picturebox,我已经做了很多搜索,找不到我需要的帮助 我需要能够将一些直径为140像素的圆放在图片盒中图像的某些部分上。当鼠标单击图像时,圆圈应出现。我需要将圆圈的中心放置在鼠标单击时的位置。用户还应该能够将圆圈放置在图像上后将其拖动到其他位置 有谁能给我一些关于如何做到这一点的指导吗 提前谢谢 这可能会让你开始。在PictureBox上绘制一个简单的红色圆圈。单击 Private Sub PictureBox1_Click(sender As System.Object, e As MouseEventAr
提前谢谢 这可能会让你开始。在
PictureBox上绘制一个简单的红色圆圈。单击
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
编辑
看起来很像你要找的
我的解决方案:`
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
Private Sub PictureBox1\u MouseDown(ByVal sender作为对象,ByVal e作为System.Windows.Forms.MouseEventArgs)处理PictureBox1.MouseDown
'单击鼠标时开始创建圆
PictureBox1.Refresh()'删除上一个矩形
Xstart=e.X
Ystart=e.Y
bRB=真
端接头
私有子PictureBox1\u MouseMove(ByVal sender作为对象,ByVal e作为System.Windows.Forms.MouseEventArgs)处理PictureBox1.MouseMove
'将圆拖动到选定区域上
如果是bRB那么
PictureBox1.Refresh()'删除上一个矩形
选择案例e.X
病例<0
RBRectangle.X=0
'RBRectangle.Width=Xstart
RB矩形。宽度=140
案例0到Xstart
RBRectangle.X=e.X
'RBRectangle.Width=Xstart-e.X
RB矩形。宽度=140
案例Xstart到PBWidth
RBRectangle.X=Xstart
'RBRectangle.Width=e.X-Xstart
RB矩形。宽度=140
大小写宽度>PBW
RBRectangle.X=Xstart
'RBRectangle.Width=PBWidth-Xstart
RB矩形。宽度=140
结束选择
选择案例e.Y
病例<0
RBRectangle.Y=0
'RBRectangle.Height=Ystart
RB矩形。高度=140
案例0至Ystart
RBRectangle.Y=e.Y
'RBRectangle.Height=Ystart-e.Y
RB矩形。高度=140
箱子从一开始到另一高度
RBRectangle.Y=Ystart
'RBRectangle.Height=e.Y-Ystart
RB矩形。高度=140
箱子的高度>PBH
RBRectangle.Y=Ystart
'RBRectangle.Height=PBHeight-Ystart
RB矩形。高度=140
结束选择
PictureBox1.CreateGraphics.Drumellipse(RBPen,RBRectangle)
如果结束
端接头
私有子PictureBox1\u MouseUp(ByVal sender作为对象,ByVal e作为System.Windows.Forms.MouseEventArgs)处理PictureBox1.MouseUp
'将矩形中的区域显示为新图像
将裁剪的BM变暗为位图
如果是bRB那么
bRB=错误
裁剪bm=新位图(RBRectangle.Width_
(1.高度)
如果结束
端接头
试试这个:
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
您是否已经有任何代码示例,或者您是否希望有人为您编写方法??您可能希望从System.Drawing.Graphics:)开始…您是否希望有人为您编写方法??他很可能在期待其他人……不,我没有期待有人为我写这个方法。如果你注意到我的问题,我只是想寻求指导。谢谢你的帮助。这个链接非常有用!希望看到您的解决方案并将此问题标记为已回答