Using Transparent Controls (Access 95 and 97)

Take the following steps to add transparent controls, with special effects. The controls will have a shape and some text, and they will paint on top of the existing Lead1 control.

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. Name the controls Lead2 and Lead3. You can put the controls anywhere on the form, because they are sized and positioned at run time.

3. Code the Lead1 control's Paint event as follows:

Private Sub Lead1_Paint()
   'Paint the transparent controls whenever we paint Lead1.
   Lead2.ForceRepaint
   Lead3.ForceRepaint
End Sub

4. Add a command button that will create and paint the special effects. Code its click event as follows:

Private Sub Command3_Click()
   'Declare local variables
   Dim LabelWidth, LabelHeight

   'Avoid extra repaints.
   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

   'Position Lead2 and Lead3.
   Lead2.Width = Lead1.Width / 2
   Lead2.Height = Lead1.Height / 2
   Lead2.Left = Lead2.Width / 2
   Lead2.Top = Lead2.Height / 2
   Lead3.Width = Lead2.Width
   Lead3.Height = Lead2.Height
   Lead3.Left = Lead2.Left
   Lead3.Top = Lead2.Top

   'Load an image into Lead1, and paint it.
   Lead1.Load "d:\lead\images\image1.cmp", 0, 0, 1
   Lead1.ForceRepaint

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

   'First, we need to create the bitmaps.
   LabelWidth = Lead2.ScaleWidth
   LabelHeight = Lead2.ScaleHeight
   Lead2.CreateBitmap LabelWidth, LabelHeight, 24
   Lead3.CreateBitmap LabelWidth, LabelHeight, 24

   'Fill it with black, which we will make transparent.
   Lead2.Fill RGB(0, 0, 0)
   Lead2.BitmapEnableTransparency = True
   Lead2.BitmapTransparentColor = RGB(0, 0, 0)
   Lead3.Fill RGB(0, 0, 0)
   Lead3.BitmapEnableTransparency = True
   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 = LabelWidth
   Lead2.ShapeHeight = LabelHeight

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

   'Shape fill pattern
   Lead2.PatternStyle = EFX_PATTERN_TRANSPARENT

   'Draw the shape.
   Lead2.DrawShape EFX_SHAPE_STAR4, 0

   'Draw text into Lead3.
   'Specify the text, font, and styles
   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 = LabelWidth
   Lead3.TextHeight = LabelHeight

   '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, LabelWidth, LabelHeight
   Lead3.DrawText "Text", 0

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

5. Run your program to test it.