Transparent form with solid text

timothyl

Registered User.
Local time
Today, 05:39
Joined
Jun 4, 2009
Messages
92
Hello, has anyone seen or have a link to or now how to make a transparent form that show the text from a text box. I have found various code for a transparent form but you can not display text on it, which I need to do, i.e I need to place text boxes on a transparent form and have only the text show up like the side bar in vista. Is this possible?. Any help pointing me in the right direction is appreciated.
 
If I had to solve the problem you describe I would use a .NET language, not Access and VBA.
 
Can you simulate what you are attempting to do by way of an image?
 
Hello, has anyone seen or have a link to or now how to make a transparent form that show the text from a text box. I have found various code for a transparent form but you can not display text on it, which I need to do, i.e I need to place text boxes on a transparent form and have only the text show up like the side bar in vista. Is this possible?. Any help pointing me in the right direction is appreciated.
i didn't even know that transparent forms were possible. havce you tried making the SECTIONS of the form transparent instead of the object itself?
 
i didn't even know that transparent forms were possible. havce you tried making the SECTIONS of the form transparent instead of the object itself?

Transparent/Transluscent forms are certainly possible; I use them often. From what I've read, you can only pass the HWND ID of a form to the appropriate API functions that render the transparency but you can't do so with a control.

One trick that I do is to fake it using images.

For example, if I want part of a form to be disabled until the user does some action, the boring way is to have the disabled section greyed out or not visible. The cool way is to put a transluscent "screen" over the section (but not the whole form). What I do sometimes is to make the whole form translucent, then do a screen capture of the form and crop it to isolate the section that I want to be transluscent. I'll then put that on the form as an image and then set the image to not be visible once the user has completed the appropriate action.

I will point out that this works great if the text boxes you are hiding are blank before the user is allowed to use them. If there has to be text that will only be known at runtime then this won't work.


Without further detail of what Timothy wants to achieve, it's hard to know if the method would be appropriate.

SHADOW
 
thanks for advice, but i'll stick with the boring method. it's easier on me..
 
thanks for advice, but i'll stick with the boring method. it's easier on me..

It certainly is easier and less time-consuming. The question is who is the intended audience for the database. If it's internal, then using a basic Windows look is adequate. If it's for a commercial application made using Access, then you would probably want to jazz up the user iterface beyond the basic look to give users an experience that is more consistent with the "web 2" world.

Or put differently, using the Windows look was great for Windows 98. In the world where people are using Vista, you want to use some of the effects that users are used to during basic computer usage (screens that fade it and out, partial trasparency and so on) so your application doesn't look dated.

SHADOW
 
Hello every one, thanks for responding, I keep finding code for trasparent and translucent forms but there all written in VB 6.0, here is a version , I pasted it in to a module then called the opaqe version like so

MakeOpague"o"

But nothing happens no error just my plain old form. Tryed various number still nothing, can some one tell me if I am using this correctly, also not sure if VB translates directly to Access. Thank you all. Tim

Code:
Option Explicit

Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Private Declare Function UpdateLayeredWindow Lib "user32" (ByVal hwnd As Long, ByVal hdcDst As Long, pptDst As Any, psize As Any, ByVal hdcSrc As Long, pptSrc As Any, crKey As Long, ByVal pblend As Long, ByVal dwFlags As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
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 LWA_COLORKEY = &H1
Private Const LWA_ALPHA = &H2
Private Const ULW_COLORKEY = &H1
Private Const ULW_ALPHA = &H2
Private Const ULW_OPAQUE = &H4
Private Const WS_EX_LAYERED = &H80000

Public Function isTransparent(ByVal hwnd As Long) As Boolean
On Error Resume Next
Dim Msg As Long
Msg = GetWindowLong(hwnd, GWL_EXSTYLE)
If (Msg And WS_EX_LAYERED) = WS_EX_LAYERED Then
  isTransparent = True
Else
  isTransparent = False
End If
If Err Then
  isTransparent = False
End If
End Function

Public Function MakeTransparent(ByVal hwnd As Long, Perc As Integer) As Long
Dim Msg As Long
On Error Resume Next
If Perc < 0 Or Perc > 255 Then
  MakeTransparent = 1
Else
  Msg = GetWindowLong(hwnd, GWL_EXSTYLE)
  Msg = Msg Or WS_EX_LAYERED
  SetWindowLong hwnd, GWL_EXSTYLE, Msg
  SetLayeredWindowAttributes hwnd, 0, Perc, LWA_ALPHA
  MakeTransparent = 0
End If
If Err Then
  MakeTransparent = 2
End If
End Function

Public Function MakeOpaque(ByVal hwnd As Long) As Long
Dim Msg As Long
On Error Resume Next
Msg = GetWindowLong(hwnd, GWL_EXSTYLE)
Msg = Msg And Not WS_EX_LAYERED
SetWindowLong hwnd, GWL_EXSTYLE, Msg
SetLayeredWindowAttributes hwnd, 0, 0, LWA_ALPHA
MakeOpaque = 0
If Err Then
  MakeOpaque = 2
End If
End Function
 
I believe that the above API calls to set transparency in Access will require that the form's popup property = true. Also, all controls on the form will have the same degree of transparency as the form itself.

And try this code...
Code:
[FONT="Verdana"][SIZE="1"]Private Const GWL_EXSTYLE = (-20)
Private Const LWA_COLORKEY = 1
Private Const LWA_ALPHA = 2
Private Const WS_EX_LAYERED = &H80000

Private Declare Function apiGetWindowLong Lib "user32" Alias "GetWindowLongA" ( _
   ByVal hwnd As Long, _
   ByVal nIndex As Long) As Long

Private Declare Function apiSetLayeredWindowAttributes Lib "user32" Alias "SetLayeredWindowAttributes" ( _
   ByVal hwnd As Long, _
   ByVal Color As Long, _
   ByVal AlphaPercent As Byte, _
   ByVal Alpha As Long) As Boolean

Private Declare Function apiSetWindowLong Lib "user32" Alias "SetWindowLongA" ( _
   ByVal hwnd As Long, _
   ByVal nIndex As Long, _
   ByVal dwNewLong As Long) As Long
   
'  Setting OpacityPercent to zero makes the form fully transparent.
'  Setting OpacityPercent to 100 makes the form fully opaque.
'  This only has an affect on forms whose PopUp property is True.
   
   
Public Sub SetOpacity(frm As Access.Form, OpacityPercent As Byte)
   ' Ensure frm is a PopUp form. Raise an error if it is not.
   If Not frm.Popup Then
      err.Raise 5, , "Invalid argument." & vbCrLf & Namespace$ & " cannot SetOpacity on form " & frm.Name & ". PopUp form required."
   Else
      ' Force OpacityPercent between 0 and 100.
      If OpacityPercent > 100 Then OpacityPercent = 100
      If OpacityPercent < 0 Then OpacityPercent = 0
      
      ' Convert supplied percentage value to one ranging between 0 and 255 for apiSetLayeredWindowAttributes
      Dim iAlpha As Integer
      iAlpha = (OpacityPercent / 100) * 255
      ' Get forms current extended attributes
      Dim attrib As Long
      attrib = apiGetWindowLong(frm.hwnd, GWL_EXSTYLE)
      ' Set form to have extended layered attribute
      apiSetWindowLong frm.hwnd, GWL_EXSTYLE, attrib Or WS_EX_LAYERED
      ' Set opacity
      apiSetLayeredWindowAttributes frm.hwnd, RGB(0, 0, 0), iAlpha, LWA_ALPHA
   End If
End Sub

[/SIZE][/FONT]
 
lagbolt, thank you for the code that worked, alas I can't do what I had hoped, which was to take the transparent form and also hide the Access window and match the text boxes to the input form of a data system we use here and auto populate it with the data in access. I had hoped the data would "shine through". I thought I was being clever. But no I was'nt. Thanks again
 

Users who are viewing this thread

Back
Top Bottom