Microsoft KB Archive/71489

= How to Create Flashing/Rotating Rubber-Band Box in VB =

Article ID: 71489

Article Last Modified on 12/12/2003

-

APPLIES TO


 * Microsoft Visual Basic 2.0 Standard Edition
 * Microsoft Visual Basic 3.0 Professional Edition
 * Microsoft Visual Basic 2.0 Professional Edition
 * Microsoft Visual Basic 3.0 Professional Edition
 * Microsoft Visual Basic 1.0 Standard Edition

-



This article was previously published under Q71489



SUMMARY
Several 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 INFORMATION
By 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:

  Draw a line using:      DrawStyle = 2 {Dot}  Save the [form].DrawMode and the [form].DrawStyle. Set the [form].DrawMode = 6 {Inverse}. Set [form].DrawStyle = 0 {Solid}. Draw the same line as in step 1. Reset the properties saved in step 2.</li> Delay some time interval.</li> Repeat starting at step 2.</li></ol>

The following code demonstrates the rotating (flashing) border. Pressing the mouse button and then dragging the cursor some distance will create a dotted line. Releasing the button will display a rotating rubber-band box.

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 query words: 2.00 3.00

Keywords: KB71489

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.