Solved

Transparent Background

Posted on 2003-11-05
5
511 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
Comment Utility
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
Comment Utility
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
Comment Utility
0
 
LVL 44

Expert Comment

by:Arthur_Wood
Comment Utility
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
Comment Utility
Thanks to all who replied. The accepted answer worked fine for me!

Canon
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
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…
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…

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now