473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

transparent backcolor


Hi

how can i make the backcolor of a form transparent

best regards
Henrik
Jul 17 '05 #1
2 7363
On Fri, 2 Jan 2004 10:56:02 +0100, "Henrik"
<ds*******@vip.cybercity.dk> wrote:

Hi

how can i make the backcolor of a form transparent


Here is some code that someone posted some time ago
- followed by another demo

Notice the MouseMove
- it shows that, although transparent, it is still 'on top'

The second Demo produces a 'shaped' Form
- that does _not_ get the mouse events in the transparent area

Option Explicit

Private Declare Function SetWindowLong _
Lib "user32" Alias "SetWindowLongA" ( _
ByVal hwnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long

Private Const GWL_EXSTYLE = (-20)
Private Const WS_EX_TRANSPARENT = &H20&

Public Sub MakeTransparent(frmIn As Form)
' Comments : Sets the form's style to be transparent. This call
should
' be made before the form is shown, for example in the
Load
' event
' Parameters: frmIn - form to modify
' Returns : Nothing
' Source : Total VB SourceBook 6
'
Dim lngResult As Long

On Error GoTo PROC_ERR

lngResult = SetWindowLong(frmIn.hwnd, _
GWL_EXSTYLE, _
WS_EX_TRANSPARENT)

PROC_EXIT:
Exit Sub

PROC_ERR:
MsgBox "Error: " & Err.Number & ". " & Err.Description, , _
"MakeTransparent"
Resume PROC_EXIT

End Sub
Private Sub Form_Load()
Call MakeTransparent(Me)
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As
Single, Y As Single)
MsgBox "Mouse Move"
End Sub

====== SECOND EXAMPLES =====

Option Explicit

' from Mike Williams

Private Declare Function CreateEllipticRgn _
Lib "gdi32" ( _
ByVal X1 As Long, _
ByVal Y1 As Long, _
ByVal x2 As Long, _
ByVal y2 As Long _
) As Long
Private Declare Function SetWindowRgn _
Lib "user32" ( _
ByVal hWnd As Long, _
ByVal hRgn As Long, _
ByVal bRedraw As Long _
) As Long

Sub MakeMeRound(TheControl As Object)
Dim hRegion As Long, lResult As Long
TheControl.Height = TheControl.Width
hRegion = CreateEllipticRgn(0, 0, TheControl.Width \ _
Screen.TwipsPerPixelX, TheControl.Height \ _
Screen.TwipsPerPixelY)
lResult = SetWindowRgn(TheControl.hWnd, hRegion, True)
End Sub

Private Sub Command1_Click()
MakeMeRound Me
End Sub

Jul 17 '05 #2
> how can i make the backcolor of a form transparent

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 Form (actually any container; Frame, PictureBox, etc.) as the
argument like so

MakeContainerTransparent Form1

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
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Paul Schnitter | last post by:
Update: My custom control is based on the article "Creating Visual Basic .NET controls from scratch" in "Adventures in .NET" on MSDN. It is designed to be a replacement for the VB6 shape...
2
by: Alex Gray | last post by:
Hi, I'm trying to make my PictureBox transparent to the BackgroundImage of the Form, not the BackColor of the form. Here's what i have: ---------------------------------------------------...
1
by: Efkas | last post by:
My application have some level : 1. MyButton class with Label inheritance 2. MyComponent as User Control loading and positionning some of MyButtons 3. MyApp loading and positionning MyComponent ...
7
by: Peter Oliphant | last post by:
Using MakeTransparent one can supposedly turn a color used in a Bitmap to transparent. But, it looks to me like all it does it set these pixels to the color BackColor of the Control it's attached...
4
by: jcrouse | last post by:
I am using the following code to move a label on a form at runtime: If myMousedown = lblP1JoyRight.Name Then If lblP1JoyRight.BackColor.Equals(Color.Transparent) Then bTransCk = True ...
2
by: Dean Slindee | last post by:
It appears that I have two routines that don't play well together! First routine: a form's background is shaded with a gradient color. Second routine: then, the background of all labels on the...
2
by: edoepke | last post by:
VISUAL BASIC ONLY: I have Googled until my fingers are sore. Is there a way to make a ListBox or TextBox control transparent (ie: transparent background)? I know it's a function of Framework that...
2
by: Pascal | last post by:
Je veux que mes label soit transparent aussi sur mes picturebox alors j'écris : i want my labels to be transparent on my pictureboxes so i wrote : Private Sub Form1_Load(ByVal sender As Object,...
4
by: ray well | last post by:
in my app i need to make a RichTextbox control transparent. i need it to be a like a pane of glass lying on a sheet of paper, where u can see everything on the sheet of paper not covered by text...
3
by: vul | last post by:
I used to use creating headers (label at the top of the screen) for VB6 forms as 2 labels shifted a little bit with different for colors to get a simulation of a shadow. I set BackColor of both...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.