grp3

 

Draw A Dotted Selection Box


Draw A Dotted Selection Box

Author: Customized Software

This code shows how to draw a selection box, like the dotted lines that
appear in some graphics programs when the user select part of a picture.

 

Preparations

Add 1 Picture Box to your form.


Form Code

Dim X1 As Integer, X2 As Integer, Y1 As Integer, Y2 As Integer
Dim SelectBox As Boolean

Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, _
X As Single, Y As Single)
'Set the drawmode to inverse. Since inverse draws using the opposite
'color it is visible and when drawn over itself becomes invisible
'without disturbing other graphic
Picture1.DrawMode = 6
'Draw style to dots
Picture1.DrawStyle = 2
'Check if a Select Box is already drawn
If X2 > 0 Then Picture1.Line (X1, Y1)-(X2, Y2), , B
'Reset all the values to the current point
X1 = X
Y1 = Y
X2 = X
Y2 = Y
End Sub

Private Sub Picture1_MouseMove(Button As Integer, Shift _
As Integer, X As Single, Y As Single)
'Check that left mouse button is pushed
If Button = 1 Then
Picture1.Line (X1, Y1)-(X2, Y2), , B
X2 = X
Y2 = Y
Picture1.Line (X1, Y1)-(X, Y), , B
End If

End Sub