James Rose Posted January 5, 2010 Share Posted January 5, 2010 Hey gang, It's perfectly easy to set the opactiy of a form, but I'd like to make text (label or printed on the form) that is also partially opaque. Any thoughts? Link to comment https://www.neowin.net/forum/topic/862666-vbnet-label-opacity/ Share on other sites More sharing options...
0 Rohdekill Posted January 5, 2010 Share Posted January 5, 2010 You could always use a lighter font color. I'm sure CSS could do it. But, the idea is to make it so that your viewers CAN read it. Why would you want to make it more difficult for anyone? Link to comment https://www.neowin.net/forum/topic/862666-vbnet-label-opacity/#findComment-592074160 Share on other sites More sharing options...
0 James Rose Posted January 6, 2010 Author Share Posted January 6, 2010 Oops, my bad. This is a Windows application. You're right Rohdenkill, css would fix this if it was a web app. Link to comment https://www.neowin.net/forum/topic/862666-vbnet-label-opacity/#findComment-592079192 Share on other sites More sharing options...
0 +Majesticmerc MVC Posted January 6, 2010 MVC Share Posted January 6, 2010 Have you tried setting the BackColor and ForeColor to something with an alpha value <255? Long shot but it might work, although I suspect that the alpha channel will get ignored. Alternatively, what about using The "Transparent/Translucent" label control from The Code Project. Its unlicenced and you have free access to the source so you can make any necessary adjustments. If you don't like either of those or they don't work, you could try just creating a class that inherits System.Windows.Forms.Label and override the OnPaint method to draw the label with opacity. Link to comment https://www.neowin.net/forum/topic/862666-vbnet-label-opacity/#findComment-592079388 Share on other sites More sharing options...
0 James Rose Posted January 7, 2010 Author Share Posted January 7, 2010 Majesticmerc, I will look into both of these ideas. Thank you very much, James Link to comment https://www.neowin.net/forum/topic/862666-vbnet-label-opacity/#findComment-592083880 Share on other sites More sharing options...
0 +Majesticmerc MVC Posted January 7, 2010 MVC Share Posted January 7, 2010 You're more than welcome :) Link to comment https://www.neowin.net/forum/topic/862666-vbnet-label-opacity/#findComment-592085316 Share on other sites More sharing options...
0 KayMan2K Posted January 19, 2010 Share Posted January 19, 2010 the simple answer is: no, if you are using Windows Forms. yes, if you are using Windows Presentation Foundation. the more complicated answer with Windows Forms is that it is drawn top-down, not bottom-up. you can't set transparency of a label over another control because the control on the bottom won't necessarily be drawn first... or at all. this is not true for top level windows. if you change the opacity of a label, some controls... like the Form itself, will fake it with some trickery. more fundamentally, WinForms is a wrapper for the Win32 API and that has limitations.. like alpha transparency for non top-level windows. if you see another program draw with control-level opacity, they are using some custom drawing code to make it happen - which can get very complex. the Windows Presentation Foundation, on the other hand, is a wrapper for the DirectX APIs, which support full transparency and are drawn bottom-up. if you want to get fancy with your uis, use WPF. Link to comment https://www.neowin.net/forum/topic/862666-vbnet-label-opacity/#findComment-592124816 Share on other sites More sharing options...
0 Firethorne Posted January 22, 2010 Share Posted January 22, 2010 For WPF, yeah it is pretty simple. For Winforms, make your own control that overrides OnPaint and OnPaintBackground appropriately. Here's something that I've used once or twice. Credit to Rick Strahl for C# version at http://www.west-wind.com/WebLog/posts/247977.aspx Imports System Imports System.Drawing Imports System.Windows.Forms ' <summary> ' A label that can be transparent. ' </summary> Public Class TransparentLabel Inherits Control ' <summary> ' Creates a new "TransparentLabel" instance. ' </summary> Public Sub New() TabStop = False Dim transparencyValue As Integer = 15 '0 is all transparent, 255 is solid ForeColor = Color.FromArgb(transparencyValue, ForeColor.R, ForeColor.G, ForeColor.B) End Sub ' <summary> ' Gets the creation parameters. ' </summary> Protected Overrides ReadOnly Property CreateParams() As CreateParams Get Dim cp As CreateParams = MyBase.CreateParams cp.ExStyle = cp.ExStyle Or &H20 Return cp End Get End Property ' <summary> ' Paints the background. ' </summary> ' <param name="e">E.</param> Protected Overrides Sub OnPaintBackground(ByVal e As PaintEventArgs) ' do nothing End Sub ' <summary> ' Paints the control. ' </summary> ' <param name="e">E.</param> Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs) Using brush As SolidBrush = New SolidBrush(ForeColor) e.Graphics.DrawString(Text, Font, brush, -1, 0) End Using End Sub End Class Link to comment https://www.neowin.net/forum/topic/862666-vbnet-label-opacity/#findComment-592140592 Share on other sites More sharing options...
Question
James Rose
Hey gang,
It's perfectly easy to set the opactiy of a form, but I'd like to make text (label or printed on the form) that is also partially opaque. Any thoughts?
Link to comment
https://www.neowin.net/forum/topic/862666-vbnet-label-opacity/Share on other sites
7 answers to this question
Recommended Posts