Visualizzazione dei risultati da 1 a 6 su 6
  1. #1

    [VB6] Form MDI figlio trasparente

    E' possibile rendere trasparente la parte background di un form figlio? (gli oggetti invece si devono vedere)

  2. #2
    Moderatore di Programmazione L'avatar di alka
    Registrato dal
    Oct 2001
    residenza
    Reggio Emilia
    Messaggi
    24,472
    VB6?
    MARCO BREVEGLIERI
    Software and Web Developer, Teacher and Consultant

    Home | Blog | Delphi Podcast | Twitch | Altro...

  3. #3
    Originariamente inviato da alka
    VB6?
    purtroppo non me lo inserisce, devo prima confermare la nuova discussione, poi modificare il titolo.
    PS: uso firefox

  4. #4
    up

  5. #5
    Utente di HTML.it L'avatar di LMondi
    Registrato dal
    Sep 2004
    Messaggi
    1,291
    Ciao Luciano79,
    Il seguente è un esempio trovato tempo fa sulla rete, è funzionante.
    Inserisci dei controlli sulla Form ... e poi fa click sulla medesima.
    codice:
    Private Const REG_OR = 2
    Private Const REG_MIN = 4
    Private Const HWND_TOPMOST = -1
    Private Const HWND_NOTOPMOST = -2
    Private Const SWP_NOMOVE = &H2
    Private Const SWP_NOSIZE = &H1
    Private Const TOPMOST_FLAGS = SWP_NOMOVE Or SWP_NOSIZE
    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 Boolean) As Long
    Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
    Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, Y, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
    
    Dim GlassForm As Long
    '-----------------------------------------------------------------------------
    Private Sub Form_Click()
    TraspGlass 1
    ' TraspGlass 0 x tornare allo stato precedente non-glass
    ' TraspGlass 1 ' ...Glass PARZIALE (Resta la caption del form)
    ' TraspGlass 2 ' ...Glass TOTALE (restano solo i controlli senza form)
    End Sub
    '-----------------------------------------------------------------------------
    Private Sub Form_Initialize()
    
        Me.Height = 3600
        Me.Width = 4800
        
        Me.ScaleMode = vbPixels     ' Non modificare!!!
        Me.Caption = "Un click con il tasto del mouse su questo form..."
    
    End Sub
    '-----------------------------------------------------------------------------
    Private Sub TraspGlass(GlassFX As Integer)
    
        Dim w As Single, h As Single, Contorno As Single, topEye As Single
        Dim i As Long, k As Long, n As Long, q As Long
        Dim PosTop As Double, PosLeft As Double
        
        ' Conversione su assi X/Y | width/height | scalewidth/scaleheight
        w = ScaleX(Width, vbTwips, vbPixels)
        h = ScaleY(Height, vbTwips, vbPixels)
        
        ' Verifica lo stato...
        If GlassFX = 0 Then
            GlassForm = CreateRectRgn(0, 0, w, h)
            SetWindowRgn hwnd, GlassForm, True
            Exit Sub
        End If
        
        GlassForm = CreateRectRgn(0, 0, 0, 0)
        Contorno = (w - ScaleWidth) / 2
        topEye = h - Contorno - ScaleHeight
        
        If GlassFX = 1 Then
            k = CreateRectRgn(0, 0, w, h)
            n = CreateRectRgn(Contorno, topEye, w - Contorno, h - Contorno)
            CombineRgn GlassForm, k, n, REG_MIN
        End If
        
        ' Traspone la nuova regione sul form...
        For i = 0 To Me.Controls.Count - 1
            If Me.Controls(i).Visible = True Then
                PosLeft = ScaleX(Me.Controls(i).Left, Me.ScaleMode, vbPixels) + Contorno
                PosTop = ScaleX(Me.Controls(i).Top, Me.ScaleMode, vbPixels) + topEye
                q = CreateRectRgn(PosLeft, PosTop, _
                PosLeft + ScaleX(Me.Controls(i).Width, Me.ScaleMode, vbPixels), PosTop + ScaleY(Me.Controls(i).Height, Me.ScaleMode, vbPixels))
                CombineRgn GlassForm, q, GlassForm, REG_OR
            End If
        Next
        
        ' Esegue...
        SetWindowRgn hwnd, GlassForm, True
    
    End Sub
    '-----------------------------------------------------------------------------
    Private Sub Form_Load()
        ' Centra il form
        CentraForm Form1
        ' On Top
        MakeTopMost Me.hwnd
    End Sub
    '-----------------------------------------------------------------------------
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
        ' Scarca l'oggetto GlassForm dalla memoria.
        SetWindowRgn hwnd, 0, False
        DeleteObject GlassForm
        ' Scarica il form dalla memoria
        Unload Form1
        Set Form1 = Nothing
    End Sub
    '-----------------------------------------------------------------------------
    Public Sub CentraForm(MyForm As Form)
        ' Centra il form
        MyForm.Top = (Screen.Height - MyForm.Height) / 2
        MyForm.Left = (Screen.Width - MyForm.Width) / 2
    End Sub
    '-----------------------------------------------------------------------------
    Sub MakeNormal(Handle As Long)
        SetWindowPos Handle, HWND_NOTOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS
    End Sub
    '-----------------------------------------------------------------------------
    Sub MakeTopMost(Handle As Long)
        SetWindowPos Handle, HWND_TOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS
    End Sub
    LM

  6. #6
    Grazie mille per la risposta, però non riesco ad ottenere proprio quello che voglio.
    Facendo così mi scompare lo sfondo della form figlia e rimangono gli oggetti contentuti (fin qui è ok), ma al posto di vedere quello chè c'è sotto (ovvero la form MDI) vedo oltre, ovvero in quello spazio rende invisibile anche la form MDI!

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.