Transparent Background

Posted on 2003-11-05
Last Modified: 2010-05-01
Hi All, is there a simple way to have a background image on a form to be visible behind a Frame ? I have a frame with some labels and command buttons on it. The background of the frame is kind of large and I want to be able to view the form background image that was placed there. So, just want to be able to get rid of the color background in a Frame to see the form background image!

Hope this makes sense ?


Question by:Canon
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 16

Expert Comment

ID: 9687477
If you change frame to transparent (with API calls it would be possible) you will not see labels any more.
One possible solution is replace the frame control with a pair of shape controls emulating the shape.
LVL 14

Accepted Solution

aelatik earned 200 total points
ID: 9687498
This works allright, found it on :

Option Explicit

Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
Private Declare Function GetPixel Lib "gdi32" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Long) As Long
Private CtrlDc, lHoch, lBreit, lTemp, lSkin, lStart, lZeile, lSpalte, lBackColor As Long

Private Sub Form_Load()
    Frame1.BackColor = &HFF&
    FrameTransparent Frame1
End Sub

Public Function FrameTranz(Ctrl As Frame) As Long
    lSkin = CreateRectRgn(0, 0, 0, 0)
        With Ctrl
            lHoch = .Height / Screen.TwipsPerPixelY
            lBreit = .Width / Screen.TwipsPerPixelX
            CtrlDc = GetDC(.hwnd)
            lBackColor = Ctrl.BackColor
        For lZeile = 0 To lHoch - 1
            lSpalte = 0
            Do While lSpalte < lBreit
                Do While lSpalte < lBreit And GetPixel(CtrlDc, lSpalte, _
                    lZeile) = lBackColor
                    lSpalte = lSpalte + 1
                If lSpalte < lBreit Then
                    lStart = lSpalte
                Do While lSpalte < lBreit And GetPixel(CtrlDc, lSpalte, _
                    lZeile) <> lBackColor
                    lSpalte = lSpalte + 1
                If lSpalte > lBreit Then lSpalte = lBreit
                    lTemp = CreateRectRgn(lStart, lZeile, lSpalte, lZeile + 1)
                    Call CombineRgn(lSkin, lSkin, lTemp, 2)
                    Call DeleteObject(lTemp)
                End If
        Next lZeile
    End With
    FrameTranz = lSkin
End Function

Public Sub FrameTransparent(Ctrl As Frame)
    Dim lSkin As Long
        Ctrl.Visible = True
        lSkin = FrameTranz(Ctrl)
        Call SetWindowRgn(Ctrl.hwnd, lSkin, True)
End Sub
LVL 16

Expert Comment

ID: 9687513
LVL 44

Expert Comment

ID: 9687664
note of caution---this line:

Private CtrlDc, lHoch, lBreit, lTemp, lSkin, lStart, lZeile, lSpalte, lBackColor As Long

ONLY declarse lBackColor As Long, the other variables are ALL declared as VARIANTs.

VB 6 does NOT support multiple declarations in one line, like that.


Private CtrlDc as Long, lHoch as Long, lBreit as Long, lTemp as Long, lSkin as Long, lStart as Long, lZeile as Long, lSpalte as Long, lBackColor As Long


Private CtrlDc as Long
Private lHoch as Long
Private lBreit as Long
Private lTemp as Long
Private lSkin as Long  and so on


Author Comment

ID: 9687800
Thanks to all who replied. The accepted answer worked fine for me!


Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VBA Shell can't Find Word document 11 155
Protecting vb6 & .Net code Obfuscation 18 210
how to know if my Checkbox is True in VB6.0? 9 68
Problem to line 23 79
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question