Solved

Transparent Background

Posted on 2003-11-05
5
513 Views
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 ?

Thanks

Canon
0
Comment
Question by:Canon
5 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
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.
0
 
LVL 14

Accepted Solution

by:
aelatik earned 200 total points
ID: 9687498
This works allright, found it on : http://www.activevb.de/tipps/vb6tipps/tipp0575.html

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()
    Me.Show
    Frame1.BackColor = &HFF&
    DoEvents
    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
                Loop
                If lSpalte < lBreit Then
                    lStart = lSpalte
                Do While lSpalte < lBreit And GetPixel(CtrlDc, lSpalte, _
                    lZeile) <> lBackColor
                    lSpalte = lSpalte + 1
                Loop
                If lSpalte > lBreit Then lSpalte = lBreit
                    lTemp = CreateRectRgn(lStart, lZeile, lSpalte, lZeile + 1)
                    Call CombineRgn(lSkin, lSkin, lTemp, 2)
                    Call DeleteObject(lTemp)
                End If
            Loop
        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
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9687513
0
 
LVL 44

Expert Comment

by:Arthur_Wood
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.

either:

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

or:

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


AW
0
 

Author Comment

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

Canon
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

773 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