CodeItBetter Programming Another VB Programming Blog

How to draw a Dotted Selection Box

Posted on January 5, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
'Graphics - How to draw a Dotted Selection Box

Option Explicit
 
'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.

'Add a Picture Box control to your form.

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
Filed under: Graphics Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.