Re: make a frame on a form transparant
From: Randy Birch (rgb_removethis_at_mvps.org)
Date: 03/11/04
- Next message: Utada P.W. SIU: "Listbox"
- Previous message: Randy Birch: "Re: mouse wheel"
- In reply to: Rick Rothstein: "Re: make a frame on a form transparant"
- Next in thread: Rick Rothstein: "Re: make a frame on a form transparant"
- Reply: Rick Rothstein: "Re: make a frame on a form transparant"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 10 Mar 2004 20:35:52 -0500
Hi Rick ...
Two problems with that code ...
1) the frame's 'frame' disappears too. Thus, rather than the frame
background appearing transparent (which would be how I read this request),
it doesn't appear at all! (note I'm using XP with a manifest for vb6.exe -
perhaps it does work without the manifest(??)).
2) regardless, the code fails when the form has a menu at the "If
Ctrl.Container Is TheContainerObject Then..." line, since menu's don't
support the container property.
-- Randy Birch MVP Visual Basic http://vbnet.mvps.org/ Please respond only to the newsgroups so all can benefit. "Rick Rothstein" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in message news:OP#hoXwBEHA.2768@tk2msftngp13.phx.gbl... : > I want frame that is on my form to be transparant, so it picks up the : > background color i painted the form with. There doesn't seem to be a way : to : > do this. : : This is from a post I've previously offered in response to a similar : question... : : Rick - MVP : : Add a Module to your project (Project/AddModule from VB's menu) and paste : the code at the end of this message into it. To use it, simply call the Sub : with the Frame (actually any container; Form, PictureBox, etc.) as the : argument like so : : MakeContainerTransparent Frame1 : : assuming your form is named Form1. All controls on the container will show : up but the container itself won't. There is a downside to this method. : OptionButtons, CheckBoxes and Labels will have the background color of their : text portion show; you can't make them transparent using the method I : incorporate below. However, this does make it easier to read their text if a : solid background it behind them. : : Private Type POINTAPI : X As Long : Y As Long : End Type : : 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 CreatePolygonRgn _ : Lib "gdi32" _ : (lpPoint As POINTAPI, _ : ByVal nCount As Long, _ : ByVal nPolyFillMode As Long) _ : As Long : : Private Declare Function CombineRgn _ : Lib "gdi32" _ : (ByVal hDestRgn As Long, _ : ByVal hSrcRgn1 As Long, _ : ByVal hSrcRgn2 As Long, _ : ByVal CombineMode 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 Declare Function DeleteObject _ : Lib "gdi32" _ : (ByVal hObject As Long) _ : As Long : : Private Const RGN_OR = 2 : Private Const ALTERNATE = 1 : : Public Sub MakeContainerTransparent(TheContainerObject As Object) : Dim TPPx As Long : Dim TPPy As Long : Dim Ctrl As Control : Dim CtrlShape(3) As POINTAPI : Dim ComboReg As Long : Dim TempReg As Long : Dim ReturnVal As Long : Dim ContainObj As Object : Dim NotFirstControl As Boolean : If TypeOf TheContainerObject Is Form Then : Set ContainObj = TheContainerObject : Else : Set ContainObj = TheContainerObject.Parent : End If : TPPx = Screen.TwipsPerPixelX : TPPy = Screen.TwipsPerPixelY : For Each Ctrl In ContainObj.Controls : If Ctrl.Container Is TheContainerObject Then : With Ctrl : CtrlShape(0).X = .Left \ TPPx : CtrlShape(0).Y = .Top \ TPPy : CtrlShape(1).X = (.Left + .Width) \ TPPx : CtrlShape(1).Y = .Top \ TPPy : CtrlShape(2).X = (.Left + .Width) \ TPPx : CtrlShape(2).Y = (.Top + .Height) \ TPPy : CtrlShape(3).X = .Left \ TPPx : CtrlShape(3).Y = (.Top + .Height) \ TPPy : If NotFirstControl Then : TempReg = CreatePolygonRgn&(CtrlShape(0), 4&, ALTERNATE) : ReturnVal = CombineRgn(ComboReg, ComboReg, TempReg, RGN_OR) : DeleteObject TempReg : Else : ComboReg = CreatePolygonRgn&(CtrlShape(0), 4&, ALTERNATE) : NotFirstControl = True : End If : End With : End If : Next : Set Ctrl = Nothing : Set ContainObj = Nothing : SetWindowRgn TheContainerObject.hWnd, ComboReg, True : DeleteObject ComboReg : End Sub : :
- Next message: Utada P.W. SIU: "Listbox"
- Previous message: Randy Birch: "Re: mouse wheel"
- In reply to: Rick Rothstein: "Re: make a frame on a form transparant"
- Next in thread: Rick Rothstein: "Re: make a frame on a form transparant"
- Reply: Rick Rothstein: "Re: make a frame on a form transparant"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|