VB中画出圆后如何选中它呢
VB中画出圆后怎么选中它呢?
就是VB程序运行时画圆,可以在picturebox里画吧?(或者其他控件?)然后程序运行时可能需要鼠标选中这个画的圆。
要这么弄呢?
------解决方案--------------------
一个利用 Shape 控件做的例子。点击圆内选中,可用方向键控制移动,双击 PictureBox 放弃选中。
------解决方案--------------------
能, 开销巨大.
就是VB程序运行时画圆,可以在picturebox里画吧?(或者其他控件?)然后程序运行时可能需要鼠标选中这个画的圆。
要这么弄呢?
vb
画圆
选中
------解决方案--------------------
一个利用 Shape 控件做的例子。点击圆内选中,可用方向键控制移动,双击 PictureBox 放弃选中。
Option Explicit
Private Sub Form_Load()
Shape1.Shape = 3 'Circle
Shape1.BorderColor = vbBlack
Shape1.Top = 200
Shape1.Left = 200
Shape1.Height = 2000
End Sub
Private Sub Picture1_DblClick()
Shape1.BorderWidth = 1
Shape1.BorderColor = vbBlack
End Sub
Private Sub Picture1_KeyDown(KeyCode As Integer, Shift As Integer)
If Shape1.BorderColor = vbBlack Then Exit Sub
If KeyCode = vbKeyLeft And Shape1.Left > 50 Then Shape1.Left = Shape1.Left - 50
If KeyCode = vbKeyUp And Shape1.Top > 50 Then Shape1.Top = Shape1.Top - 50
If KeyCode = vbKeyRight And Shape1.Left + Shape1.Width < Picture1.Width - 50 Then Shape1.Left = Shape1.Left + 50
If KeyCode = vbKeyDown And Shape1.Top + Shape1.Height < Picture1.Height - 50 Then Shape1.Top = Shape1.Top + 50
End Sub
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim circle_center_x As Long, circle_center_y As Long, circle_radius As Long
With Shape1
circle_radius = .Height \ 2
circle_center_x = .Left + circle_radius
circle_center_y = .Top + circle_radius
If (X - circle_center_x) ^ 2 + (Y - circle_center_y) ^ 2 < circle_radius ^ 2 Then
.BorderWidth = 5
.BorderColor = vbRed
End If
End With
End Sub
------解决方案--------------------
能, 开销巨大.
Private Type Pointer
X As Long
Y As Long
End Type
Private Declare Function CreatePolygonRgn Lib "gdi32" (lpPoint As Any, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long
Private Declare Function Polygon Lib "gdi32" (ByVal HDC As Long, lpPoint As Any, ByVal nCount As Long) As Long
Private Declare Function FillRgn Lib "gdi32" (ByVal HDC As Long, ByVal hRgn As Long, ByVal HBrush As Long) As Long
Private Declare Function GetStockObject Lib "gdi32" (ByVal nIndex As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const ALTERNATE = 1
Const WINDING = 2
Const BLACKBRUSH = 4
Const HTCAPTION = 2