Ir para conteúdo
Fórum Script Brasil

ricarmpo

Membros
  • Total de itens

    1
  • Registro em

  • Última visita

Tudo que ricarmpo postou

  1. Fala ai galera beleza ? Estou com um problema, estou tentando colocar controles (Buttons, TextBox, etc) em um Layered Form, já pesquisei bastante mais ainda nada de funcionar. Criei um form que utiliza um PNG com trasnparencia como background, a parte do PNG e da transparencia funciona perfeito, porem não consigo adicionar controles nesse form. alguém pode ajudar ? Se existir outra maneira de fazer o PNG com a transparencia funcionar e tiver como adicionar controles no form, por favor postem, realmente preciso disso. Tks #Region "Importando a API GDI" Public Class Win32 Public Enum Bool [False] = 0 [True] = 1 End Enum 'Bool Public Structure Point Public x As Int32 Public y As Int32 Public Sub New(ByVal x As Int32, ByVal y As Int32) Me.x = x Me.y = y End Sub 'New End Structure 'Point Public Structure Size Public cx As Int32 Public cy As Int32 Public Sub New(ByVal cx As Int32, ByVal cy As Int32) Me.cx = cx Me.cy = cy End Sub 'New End Structure 'Size Structure ARGB Public Blue As Byte Public Green As Byte Public Red As Byte Public Alpha As Byte End Structure 'ARGB Public Structure BLENDFUNCTION Public BlendOp As Byte Public BlendFlags As Byte Public SourceConstantAlpha As Byte Public AlphaFormat As Byte End Structure 'BLENDFUNCTION Public Shared ULW_COLORKEY As Int32 = &H1 Public Shared ULW_ALPHA As Int32 = &H2 Public Shared ULW_OPAQUE As Int32 = &H4 Public Shared AC_SRC_OVER As Byte = &H0 Public Shared AC_SRC_ALPHA As Byte = &H1 Public Declare Function UpdateLayeredWindow Lib "user32" Alias "UpdateLayeredWindow" (ByVal hwnd As IntPtr, ByVal hdcDst As IntPtr, ByRef pptDst As Point, ByRef psize As Size, ByVal hdcSrc As IntPtr, ByRef pprSrc As Point, ByVal crKey As Int32, ByRef pblend As BLENDFUNCTION, ByVal dwFlags As Int32) As Boolean Public Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal hWnd As IntPtr) As IntPtr Public Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC" (ByVal hWnd As IntPtr, ByVal hDC As IntPtr) As Integer Public Declare Function CreateCompatibleDC Lib "gdi32.dll" Alias "CreateCompatibleDC" (ByVal hDC As IntPtr) As IntPtr Public Declare Function DeleteDC Lib "gdi32.dll" Alias "DeleteDC" (ByVal hDC As IntPtr) As Boolean Public Declare Function SelectObject Lib "gdi32.dll" Alias "SelectObject" (ByVal hDC As IntPtr, ByVal hObject As IntPtr) As IntPtr Public Declare Function DeleteObject Lib "gdi32.dll" Alias "DeleteObject" (ByVal hObject As IntPtr) As Boolean End Class #End Region 'Para funcionar o PNG com trasparencia, chamar a sub LoadBackground no formload Imports System.Drawing Imports System.Drawing.Imaging Imports System.Windows.Forms Imports Common.Win32 Public Class MainForm Protected Overrides ReadOnly Property CreateParams() As CreateParams Get Dim cp As CreateParams = MyBase.CreateParams If Not Site Is Nothing Then If Not Site.DesignMode Then cp.ExStyle = cp.ExStyle Or &H80000 End If Else cp.ExStyle = cp.ExStyle Or &H80000 End If Return cp End Get End Property Protected Sub LoadBackground() Dim _background As Bitmap = BackgroundImage If Not _background Is Nothing Then If Not _background.PixelFormat = PixelFormat.Format32bppArgb Then MessageBox.Show("The bitmap must be 32bpp with alpha-channel.") Else Dim screenDc As IntPtr = GetDC(IntPtr.Zero) Dim memDc As IntPtr = CreateCompatibleDC(screenDc) Dim hBitmap As IntPtr = IntPtr.Zero Dim oldBitmap As IntPtr = IntPtr.Zero Try hBitmap = _background.GetHbitmap(Color.FromArgb(0)) oldBitmap = SelectObject(memDc, hBitmap) Dim size As New Win32.Size(_background.Width, _background.Height) Dim pointSource As New Win32.Point(0, 0) Dim topPos As New Win32.Point(Me.Left, Me.Top) Dim blend As New BLENDFUNCTION blend.BlendOp = AC_SRC_OVER blend.BlendFlags = 0 blend.SourceConstantAlpha = 255 blend.AlphaFormat = AC_SRC_ALPHA UpdateLayeredWindow(Me.Handle, screenDc, topPos, size, memDc, pointSource, 0, blend, ULW_ALPHA) Finally ReleaseDC(IntPtr.Zero, screenDc) If Not hBitmap = IntPtr.Zero Then SelectObject(memDc, oldBitmap) DeleteObject(hBitmap) End If DeleteDC(memDc) End Try End If End If End Sub Protected Overrides Sub WndProc(ByRef m As Message) If m.Msg = &H84 Then m.Result = 2 Return End If MyBase.WndProc(m) End Sub End Class
×
×
  • Criar Novo...