1 Replies - 1478 Views - Last Post: 29 January 2013 - 12:49 PM Rate Topic: -----

#1 Vishal1419  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 141
  • Joined: 19-May 12

Opacity Property and fade out effect in vb.net

Posted 29 January 2013 - 12:39 PM

I want to make fade out effect for label but it does not have any opacity property, so how can I achieve the animation or how can I create a Property for opacity
Is This A Good Question/Topic? 0
  • +

Replies To: Opacity Property and fade out effect in vb.net

#2 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3609
  • View blog
  • Posts: 12,408
  • Joined: 12-December 12

Re: Opacity Property and fade out effect in vb.net

Posted 29 January 2013 - 12:49 PM

Below is some code from this discussion. Alternatively, switch to WPF.

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

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1