How to Create Flashing/Rotating Rubber-Band Box in VBLast reviewed: June 21, 1995Article ID: Q71489 |
The information in this article applies to:
SUMMARYSeveral programs, such as Excel, create a flashing border (which appears to rotate) when selecting items of the windows when using the Edit Copy selection of the menu system. You can create a flashing, rotating border with the DrawMode and DrawStyle properties of a Visual Basic form.
MORE INFORMATIONBy drawing a dashed line on the form and then within a timer event creating a solid line on the dashed line with DrawMode set to INVERSE, you can create a special effect of a flashing border that appears to rotate. You can draw a rotating rubber-band box as follows:
In VB.EXE, create a form called Form1. On Form1, create a timer control with the name Timer1 and with an interval of 100. Duplicate the following code within the general declaration section of your code window:
Const INVERSE = 6 'Characteristic of DrawStyle property(Inverse). Const SOLID = 0 'Characteristic of DrawMode property. Const DOT = 2 'Characteristic of DrawMode property.Const TRUE = -1 Const FALSE = 0 Dim OldXSub As Single, OldY As Single, StartX As Single, StartY As Single Add the following code in the appropriate event procedures for Form1:
Sub Form_Load ()
'* Must draw a dotted line to create effect. Load a bitmap. Not
required but shows full extent of line drawing.
DrawStyle = DOT
End Sub
Sub Timer1_Timer ()
SavedDrawStyle% = DrawStyle
'* Solid is need to create the inverse of the dashed line.
DrawStyle = SOLID
'* Invert the dashed line.
Call DrawLine(StartX, StartY, OldX, OldY)
'* Restore the DrawStyle back to what it was previously.
DrawStyle = SavedDrawStyle%
End Sub
Sub Form_MouseDown (Button As Integer, Shift As Integer, X As
Single, Y As Single)
' The above Sub statement must be on just one line.
'* Don't add effect as you draw box.
Timer1.Enabled = FALSE
'* Save the start locations.
StartX = X
StartY = Y
'* Set the last coord. to start locations.
OldX = StartX
OldY = StartY
End Sub
Sub Form_MouseMove (Button As Integer, Shift As Integer, X As
Single, Y As Single)
' (The above Sub statement must be on just one line.)
'* If button is depress then...
If Button Then
'* Restore previous lines background.
Call DrawLine(StartX, StartY, OldX, OldY)
'* Draw new line.
Call DrawLine(StartX, StartY, X, Y)
'* Save coordinates for next call.
OldX = X : OldY = Y
End If
End Sub
Sub DrawLine (X1 As Single, Y1 As Single, X2 As Single, Y2 As Single)
'* Save the current mode so that you can reset it on
'* exit from this sub routine. Not needed in the sample
'* but would need it if you are not sure what the
'* DrawMode was on entry to this procedure.
SavedMode% = DrawMode
'* Set to XOR
DrawMode = INVERSE
'*Draw a box
Line (X1, Y1)-(X2, Y2), , B
'* Reset the DrawMode
DrawMode = SavedMode%
End Sub
Sub Form_MouseUp (Button As Integer, Shift As Integer, X As Single,
Y As Single)
' (The above Sub statement must be on just one line.)
StartEvent = FALSE
Timer1.Enabled = TRUE
End Sub
|
Additional reference words: 1.00 2.00 3.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |