Form1  上有一个picturebox 怎么可以使picturebox1透明而使窗体不透明,我写了一个可是窗体也被透明掉了

解决方案 »

  1.   

    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 Const RGN_OR = 2
    Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
    Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As LongDim AllowMove As BooleanPrivate Sub Form_Load()
        Dim w As Long, h As Long, i As Long, j As Long, k As Long
        Dim hdcPic As Long, hRgn As Long, tRgn As Long, lTransColor As Long    Picture1.ScaleMode = vbPixels
        Picture1.AutoSize = True
        Picture1.BorderStyle = 0
        Picture1.BackColor = Me.BackColor
        Picture1.ScaleMode = vbPixels
        Set Picture1.Picture = LoadPicture("f:\temp.gif") '加载一幅有透明效果的GIF图片
        
        Picture1.AutoRedraw = True
        hdcPic = Picture1.hdc
        lTransColor = Picture1.BackColor
        w = Picture1.ScaleX(Picture1.Picture.Width, vbHimetric, vbPixels)
        h = Picture1.ScaleY(Picture1.Picture.Height, vbHimetric, vbPixels)
        For j = 0 To h - 1
            For i = 0 To w - 1
                If GetPixel(hdcPic, i, j) <> lTransColor Then
                    If hRgn = 0 Then
                        hRgn = CreateRectRgn(i, j, i + 1, j + 1)
                    Else
                        tRgn = CreateRectRgn(i, j, i + 1, j + 1)
                        hRgn = CombineRgn(hRgn, hRgn, tRgn, RGN_OR)
                        DeleteObject tRgn
                        tRgn = 0
                    End If
                End If
            Next
        Next
        Picture1.AutoRedraw = False
        If hRgn <> 0 Then
            SetWindowRgn Picture1.hWnd, hRgn, True
            DeleteObject hRgn
        End If
    End Sub
      

  2.   

    俺不大会描述。
    想当年在大学时,俺曾经获得过最佳辩手称号,如今感觉好像那根本不是俺。真的,在机房里呆的时间长了,眼里和心里都只有代码了,要不,就是耳边那磁盘组、路由器、交换机、防火墙、IDS...等设备的交响。
      

  3.   

    是picturebox 透明还是图片透明?
      

  4.   

    一楼的好象不行啊,我刚试过了没有什么效果,我想要的是使Picturebox像image框一样放一张透明的图片进去,显示一张透明的图片
      

  5.   

    我试过了,可以的,你首先得保证是GIF图片,并且有透明效果。