VB.NET TEXTBOX TRANSPARENTE

EDELSIOBR 04/06/2012 22:57:51
#403502
Olá Amigos!
Alguém consegiu fazer um textbox ficar transparente...
Mas gostaria que ele ficasse tambem transparente na hora que estiver escrevendo dentro dele e deixasse eu aumentar o tamanho e largura do mesmo e tambem deixar selecionar a fonte e size.
Este codigo consegui deixar ele transparente qdo eu executo, mas ele fica com fundo branco quando digito dentro e tambem some tem hora o que digitei.

codigo da classe:

Public Class textbox_Transparente
Inherits System.Windows.Forms.TextBox

Protected Overrides ReadOnly Property CreateParams() As System.Windows.Forms.CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.ExStyle = cp.ExStyle Or &H20 [ô] color transparente
Return cp
End Get
End Property

Public Sub New()

Me.SetStyle(ControlStyles.SupportsTransparentBackColor, True)
Me.SetStyle(ControlStyles.ResizeRedraw, True)
Me.SetStyle(ControlStyles.UserPaint, True)
Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, False)
Me.UpdateStyles()
Me.BackColor = Color.Transparent


End Sub

Protected Overrides Sub OnPaintBackground(ByVal pevent As System.Windows.Forms.PaintEventArgs)
If MyBase.BackgroundImage IsNot Nothing Then
MyBase.OnPaintBackground(pevent)
End If
End Sub
Protected Overrides Sub OnForeColorChanged(ByVal e As System.EventArgs)
Me.Refresh()
End Sub
End Class



Obrigado a todos
PROFESSOR 29/12/2012 16:40:02
#416556
Resposta escolhida
Dá para fazer, de forma razoável, como no VB6. usando API da User32.
O código á seguir é um resumo de um artigo no CodeProject, que pode ser útil.



Public Class TransparentTextBox
Inherits TextBox

<DllImport([Ô]user32.dll[Ô], SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
End Function

Public Enum Win32
WM_PAINT = &HF
WM_PRINT = &H317
WM_HSCROLL = &H114
WM_VSCROLL = &H115
PRF_CLIENT = &H4
PRF_ERASEBKGND = &H8
End Enum

Private pictureBox As New PictureBox()

Public Sub New()
pictureBox.Dock = DockStyle.Fill
Me.Controls.Add(pictureBox)
End Sub
Protected Overrides Sub WndProc(ByRef m As Message)
MyBase.WndProc(m)
Select Case m.Msg
Case Win32.WM_PAINT

Dim bmpCaptured As New Bitmap(Me.ClientRectangle.Width, Me.ClientRectangle.Height)
Dim bmpResult As New Bitmap(Me.ClientRectangle.Width, Me.ClientRectangle.Height)
Dim r As New Rectangle(0, 0, Me.ClientRectangle.Width, Me.ClientRectangle.Height)

CaptureWindow(Me, bmpCaptured)
Me.SetStyle(ControlStyles.SupportsTransparentBackColor, True)
Me.BackColor = Color.Transparent

Dim imgAttrib As New ImageAttributes()
Dim colorMap As ColorMap() = New ColorMap(0) {}
colorMap(0) = New ColorMap()
colorMap(0).OldColor = Color.White
colorMap(0).NewColor = Color.Transparent
imgAttrib.SetRemapTable(colorMap)

Dim g As Graphics = Graphics.FromImage(bmpResult)
g.DrawImage(bmpCaptured, r, 0, 0, Me.ClientRectangle.Width, Me.ClientRectangle.Height, _
GraphicsUnit.Pixel, imgAttrib)
g.Dispose()

pictureBox.Image = DirectCast(bmpResult.Clone(), Image)
Exit Select

Case Win32.WM_HSCROLL, Win32.WM_VSCROLL

Me.Invalidate()
[ô] repaint
[ô] if you use scrolling then add these two case statements
Exit Select
End Select
End Sub

Private Shared Sub CaptureWindow(ByVal control As Control, ByRef bitmap As Bitmap)
Dim g As Graphics = Graphics.FromImage(bitmap)
Dim i As Integer = CInt(Win32.PRF_CLIENT Or Win32.PRF_ERASEBKGND)
Dim iPtr As New IntPtr(14)
Dim hdc As IntPtr = g.GetHdc()
SendMessage(control.Handle, Win32.WM_PRINT, hdc, iPtr)
g.ReleaseHdc(hdc)
g.Dispose()
End Sub
End Class


Em XP, Vista, Server 2003/2008/2012, Seven, tudo em ordem.
Agora, deverá ser testado no Win8 e posteriores, não testei ainda.
Ao que parece, a User32 e outras bibliotecas, apesar de presentes no Win8, sofreram alterações. Nem tudo funcionaria da mesma forma.
Tópico encerrado , respostas não são mais permitidas