PDA

Visualizza la versione completa : [VB]trasparenza


mhmh
31-10-2002, 13:40
ciao a tutti,come posso ottenere una form trasparente?Ho già provato in tutti i modi che conosco,ma il risultato è sempre lo stesso (cioè nada).Chi può aiutarmi?
grazie in anticipo

maleresidente
31-10-2002, 15:56
direttamente dal sito vbprogrammer ecco il codice per le forms trasparenti


' Aggiungere queste istruzioni in un Modulo
Option Explicit
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 SetWindowRgn Lib "user32" (ByVal hWnd As _
Long, ByVal hRgn As Long, ByVal bRedraw As Long) As Long

Public Sub FormTrasparente(frm As Form)
frm.ScaleMode = vbPixels
Const RGN_DIFF = 4
Const RGN_OR = 2

Dim rgn_esclusa As Long
Dim rgn_inclusa As Long
Dim rgn_combinate As Long
Dim wid As Single
Dim hgt As Single
Dim border_width As Single
Dim title_height As Single
Dim ctl_left As Single
Dim ctl_top As Single
Dim ctl_right As Single
Dim ctl_bottom As Single
Dim control_rgn As Long
Dim ctl As Control

If frm.WindowState = vbMinimized Then Exit Sub

' Crea la regione principale del form.
wid = frm.ScaleX(frm.Width, vbTwips, vbPixels)
hgt = frm.ScaleY(frm.Height, vbTwips, vbPixels)
rgn_esclusa = CreateRectRgn(0, 0, wid, hgt)

border_width = (wid - frm.ScaleWidth) / 2
title_height = hgt - border_width - frm.ScaleHeight
rgn_inclusa = CreateRectRgn(border_width, title_height, wid - border_width, _
hgt - border_width)

' Esclude la sezione inclusa da quella esclusa.
rgn_combinate = CreateRectRgn(0, 0, 0, 0)
CombineRgn rgn_combinate, rgn_esclusa, rgn_inclusa, RGN_DIFF

' Crea le regioni relative ai controlli sul form.
For Each ctl In frm.Controls
If ctl.Container Is frm Then
ctl_left = frm.ScaleX(ctl.Left, frm.ScaleMode, vbPixels) _
+ border_width
ctl_top = frm.ScaleX(ctl.Top, frm.ScaleMode, vbPixels) + title_height
ctl_right = frm.ScaleX(ctl.Width, frm.ScaleMode, vbPixels) + ctl_left
ctl_bottom = frm.ScaleX(ctl.Height, frm.ScaleMode, vbPixels) + ctl_top
control_rgn = CreateRectRgn(ctl_left, ctl_top, ctl_right, ctl_bottom)
CombineRgn rgn_combinate, rgn_combinate, control_rgn, RGN_OR
End If
Next ctl

'Limita la form alla regione
SetWindowRgn frm.hWnd, rgn_combinate, True
End Sub

' Inserire questo codice in un Form
Private Sub Form_Resize()
FormTrasparente Me
End Sub



ciao.

Nico
31-10-2002, 22:25
Ihihi che figata strusandoci un po' sopra sono anche riuscito a farlo funzionare....meglio! Ho addirittura reso trasparente tutto quanto, barra e bordi compresa :quote:

Loading