Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TRASPARENT TEXTBOX

Status
Not open for further replies.

SpiroChronis

Programmer
Mar 30, 2005
10
ZA
if you can answer this question consider yourself a legend.

i have a picturebox situated over a webbrowsing component. I need the picturebox to be transparent while still maintaining autoredraw=true.

Basically i want it to appear as though i am drawing over the webbrowser content.

I have tried so many different methods, i'm stumped. please please help
 
It may be easier than you think. Consider the SetLayeredWindowAttributes API call (a search in this forum shopuld find some examples from Hypetia and myself)
 
I originally used the setlayeredWindowAttributes API call, it worked fine, however autoredraw needed to be off. I need autoredraw on.

Another problem i encountered was that it doesn't work with windows 98!

Is there maybe a component i could use?

I have been tearing my hair out trying to figure this out
 
Works fine with autoredraw=true here - but I understand your issue with W98 ...
 
Okay, is there an example you could give me. I am trying this but it doesn't seem to work!

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 Declare Function SetLayeredWindowAttributes Lib "user32.dll" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long

Const LWA_ALPHA = &H2&
Const GWL_EXSTYLE = (-20)
Const WS_EX_LAYERED = &H80000

Private Sub Form_Load()
Dim StyleEx As Long, Opacity As Byte
Opacity = 155 '0 = transparent, 255 = opaque
StyleEx = GetWindowLong(hwnd, GWL_EXSTYLE)
StyleEx = StyleEx Or WS_EX_LAYERED
SetWindowLong Picture1.hwnd, GWL_EXSTYLE, StyleEx
SetLayeredWindowAttributes Picture1.hwnd, 0, Opacity, LWA_ALPHA
End Sub
 
Ah - you are using alpha values, when you actually want to be using a color key:
Code:
[blue]Option Explicit

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 Declare Function SetLayeredWindowAttributes Lib "user32.dll" (ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Const LWA_COLORKEY = &H1
Const LWA_ALPHA = &H2&
Const GWL_EXSTYLE = (-20)
Const WS_EX_LAYERED = &H80000

Private Sub Form_Load()
    Dim dwExStyle As Long
    ' Set up a transparent window
    dwExStyle = GetWindowLong(hWnd, GWL_EXSTYLE)
    dwExStyle = dwExStyle Or WS_EX_LAYERED
    SetWindowLong hWnd, GWL_EXSTYLE, dwExStyle
    BackColor = RGB(1, 0, 0) ' this is what will be transparant
    SetLayeredWindowAttributes hWnd, RGB(1, 0, 0), 0, LWA_COLORKEY
    
    ' render on our transparent window
    Form1.BorderStyle = 0
    Form1.FontName = "Arial Bold"
    Form1.FontSize = 18
    Print "Hello"
End Sub[/blue]
 
This is fantastic, however it make the form opaque rather than the picturebox?

What do i need to do to make just the picturebox transparent
 
Sorry that didn't make a whole lot of sense.

What i meant was the code you gave me makes the form transparent rather than the picturebox.

What do i need to do to make the picturebox transparent?
 
Where did you get the "window handle" (hwnd) for use in the SetLateredWindowAttributes() call?
 
Me? Oh, I was being lazy, and relying on the fact that code in a form can assume that all the form's properties and methods are publically available (er ... 'public' in the COM sense that I don't need to fully qualify them, i.e

hWnd = TheFormTheCodeIsIn.hWnd

which, in this example, would be Form1.hWnd)
 
Sorry, strongm. That question was a suggestion directed at "spirochronis
 
Ak=h, OK. Mind you, simply changing the hWnd to that of the picturebox won't actually help, since layered windows have to be top level windows (which a VB picture box isn't). You have to do a little bit more work. But I thought I'd leave that as an exercise for the reader ...
 
Okay now i'm confused. How do i make the picturebox in the form transparent then?
 
Novel idea, draw straight on the form? Am i heading in the right direction

However, if you click on the form, you click onto the items beneath the form.

The problem will arise when i want to draw to a specific position on the form and i can't click it
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top