Hi Phil,
Yes, WinForm controls support transparent back color. But it doesn't mean
the transparent control will show the controls under it.
To get what you want in VB.NET, I suggest that you create a WinForm and
paint the text you like on this form and show the form over the main form
of your application. We can set the form's TransparencyKey property to its
back color and its FormBorderStyle property to None, so that only the text
drawn in the form will be shown. We also need to set the ShowInTaskbar
property of the form to false in order to make the form invisible in the
taskbar.
One problem is that we need to keep the main form active when we show the
above form to display texts. To solve this problem, we could catch the
WM_NCACTIVATE message in the WndProc method within the main form and if the
value of the wParam parameter is 0, send another WM_NCACTIVATE message with
the wParam of value 1 to the main form.
The following is a sample code. It requires you to add two Buttons on the
form. When you click the Button1, a transparent form is shown displaying
"hello wold" over the Form1. When you click the Button2, the transparent
form is closed.
Public Class Form1
Private WM_NCACTIVATE As Integer = &H86
Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As
IntPtr, ByVal msg As Integer, ByVal wParam As Integer, ByVal lparam As
Integer) As Integer
Dim frm As Form
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If (frm Is Nothing) Then
frm = New Form()
End If
frm.FormBorderStyle = Windows.Forms.FormBorderStyle.None
frm.TransparencyKey = frm.BackColor
AddHandler frm.Paint, AddressOf frm_Paint
frm.Width = Me.Width
frm.Height = Me.Height
frm.TopMost = True
frm.ShowInTaskbar = False
frm.Show()
frm.Location = Me.PointToScreen(New Point(0, 0))
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
frm.Close()
frm = Nothing
End Sub
Private Sub frm_Paint(ByVal sender As Object, ByVal e As PaintEventArgs)
e.Graphics.DrawString("hello world", Me.Font, Brushes.YellowGreen,
15, 15)
End Sub
Private Sub Form1_Move(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Move
If Not (frm Is Nothing) Then
frm.Location = Me.PointToScreen(New Point(0, 0))
End If
End Sub
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
MyBase.WndProc(m)
If (m.Msg = WM_NCACTIVATE) Then
If (m.WParam.ToInt32() = 0) Then
SendMessage(Me.Handle, WM_NCACTIVATE, 1, 0)
End If
End If
End Sub
End Class
Hope this helps.
If you have any question, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.