Using Transparent Controls (Visual Basic)

Take the following steps to add transparent controls, with special effects. The transparent controls are added as child controls so that they will scroll with the parent image.

1. Start with the project that you created in Loading and Displaying an Image.

2. Add two LEAD controls, which you will set to be transparent at run time. (At design time, you can make the controls easier to see by setting the BackColor property of each control to a different color.) Add the controls as follows:

a. Add a control named Lead2 as a child control to Lead1. In other words, draw it inside the Lead1 control.

b. Add a control named Lead3 as a child control to Lead2. In other words, draw it inside the Lead2 control.

3. Add a command button and code its click event as follows:

Private Sub Command1_Click()
   Dim TestText As String
   Dim TextWidth As Single
   Dim TextHeight As Single

   Lead1.EnableMethodErrors = False
   Lead1.AutoRepaint = False
   Lead2.AutoRepaint = False
   Lead3.AutoRepaint = False

   'Make Lead2 and Lead3 transparent.
   Lead2.Transparent = True
   Lead3.Transparent = True

   'Give each control a different effect.
   Lead1.PaintEffect = EFX_EFFECT_WIPE_RECTANGLE_OUT
   Lead2.PaintEffect = EFX_EFFECT_WIPE_RECTANGLE_IN
   Lead3.PaintEffect = EFX_EFFECT_WIPE4_R_B_L_B

   Lead1.EffectDelay = 20
   Lead2.EffectDelay = 20
   Lead3.EffectDelay = 20
   Lead1.EffectGrain = 1
   Lead2.EffectGrain = 5
   Lead3.EffectGrain = 1

   ScaleMode = 1
   Lead1.ScaleMode = 1
   Lead2.ScaleMode = 1

   'Position Lead2 and Lead3 inside Lead1.
   Lead2.Width = Lead1.Width / 2
   Lead2.Height = Lead1.Height / 2
   Lead2.Top = (Lead1.Width - Lead2.Width) / 2
   Lead2.Left = (Lead1.Height - Lead2.Height) / 2

   Lead3.Top = 0
   Lead3.Left = 0
   Lead3.Width = Lead2.Width
   Lead3.Height = Lead2.Height

   'We will be drawing into the bitmaps.
   Lead2.DrawPersistence = True
   Lead3.DrawPersistence = True

   'First, we need some bitmaps.
   Lead2.ScaleMode = 3
   Lead3.ScaleMode = 3
   Lead2.CreateBitmap Lead2.ScaleWidth, Lead3.ScaleHeight, 24
   Lead3.CreateBitmap Lead3.ScaleWidth, Lead3.ScaleHeight, 24

   'Fill them with black, which we will make transparent.
   Lead2.Fill RGB(0, 0, 0)
   Lead3.Fill RGB(0, 0, 0)
   Lead2.BitmapEnableTransparency = True
   Lead3.BitmapEnableTransparency = True
   Lead2.BitmapTransparentColor = RGB(0, 0, 0)
   Lead3.BitmapTransparentColor = RGB(0, 0, 0)

   'Draw a shape into Lead2.
   'Shape background
   Lead2.ShapeBackgroundStyle = EFX_BACKSTYLE_TRANSLUCENT

   'Shape location
   Lead2.ShapeTop = 0
   Lead2.ShapeLeft = 0
   Lead2.ShapeWidth = Lead2.BitmapWidth
   Lead2.ShapeHeight = Lead2.BitmapHeight

   'Shape border
   Lead2.ShapeBorderColor = RGB(255, 0, 0)
   Lead2.ShapeBorderStyle = EFX_BORDERSTYLE_SOLID
   Lead2.ShapeBorderThickness = 5

   Lead2.PatternStyle = EFX_PATTERN_TRANSPARENT

   'Draw the shape
   Lead2.DrawShape EFX_SHAPE_STAR4, 0

   'Draw text into Lead3.
   'Specify the text, font, and styles.
   TestText = "Text"
   Lead3.Font.Name = "Arial"
   Lead3.Font.Size = 40
   Lead3.TextAngle = 450
   Lead3.DrawFontColor = RGB(0, 0, 255) 'Blue
   Lead3.TextStyle = EFX_TEXTSTYLE_NORMAL
   Lead3.TextAlign = EFX_TEXTALIGN_HCENTER_VCENTER

   'Set the location for the text.
   Lead3.TextTop = 0
   Lead3.TextLeft = 0
   Lead3.TextWidth = Lead3.BitmapWidth
   Lead3.TextHeight = Lead3.BitmapHeight

   'Set the properties for drawing a rectangle behind the text..
   Lead3.DrawPenStyle = DRAWPENSTYLE_SOLID
   Lead3.DrawPenColor = RGB(255, 255, 0)
   Lead3.DrawMode = DRAWMODE_COPY_PEN

   'Draw the rectangle, then draw the text.
   Lead3.DrawRectangle 0, 0, Lead3.BitmapWidth, Lead3.BitmapHeight
   Lead3.DrawText TestText, 0

'Load an image into Lead1.
   Lead1.Load "c:\lead\images\image1.cmp", 0, 0, 1
   Lead1.PaintSizeMode = PAINTSIZEMODE_ZOOM
   Lead1.PaintZoomFactor = 150
   Lead1.ForceRepaint

   'Turn off the effects.
   Lead1.PaintEffect = EFX_EFFECT_NONE
   Lead2.PaintEffect = EFX_EFFECT_NONE
   Lead3.PaintEffect = EFX_EFFECT_NONE
End Sub

4. Run your program to test it.