Click here to Skip to main content
15,893,668 members
Articles / Multimedia / GDI+

TMDock - Dockbar samples alpha blend

Rate me:
Please Sign up or sign in to vote.
4.97/5 (20 votes)
31 Jan 2013CPOL2 min read 42.6K   2.7K   42  
Dockbar sample, shows many alpha blend functions.
Imports System.Reflection

Module Common
    Public m_Settings As TMDock.Settings
    Public oldSettings As TMDock.Settings

    Public Function HexToColor(ByVal strHex As String) As Color
        Return Color.FromArgb(Convert.ToInt32(strHex, 16))
    End Function

    Public Function ColorToHex(ByVal cColor As Color) As String
        Return Hex(cColor.ToArgb)
    End Function

    Public Function ColorToHex(ByVal R As Byte, ByVal G As Byte, ByVal B As Byte) As String
        Return Hex(CUInt((R << 16) + (G << 8) + B))
    End Function

    Public Enum AnimateWindowFlags
        AW_HOR_POSITIVE = &H1
        AW_HOR_NEGATIVE = &H2
        AW_VER_POSITIVE = &H4
        AW_VER_NEGATIVE = &H8
        AW_CENTER = &H10
        AW_HIDE = &H10000
        AW_ACTIVATE = &H20000
        AW_SLIDE = &H40000
        AW_BLEND = &H80000
    End Enum

    'Dim f1 As Form1

    Public Declare Auto Function AnimateWindow Lib "user32" (ByVal hwnd As IntPtr, _
                                                             ByVal time As Integer, _
                                                             ByVal flags As AnimateWindowFlags) As Boolean

    'Sub Main()
    '    f1 = New Form1
    '    Dim xx As Integer = Screen.PrimaryScreen.Bounds.Width - f1.Size.Width
    '    Dim yy As Integer = Screen.PrimaryScreen.Bounds.Height / 2 - (f1.Size.Height / 2)
    '    f1.Location = New Point(xx, yy)
    '    Application.Run(f1)
    'End Sub

    Sub animateWin(ByVal frmToAnimate As Form, ByVal showForm As Boolean)
        If showForm Then
            'AnimateWindow(frmToAnimate.Handle, 500, _
            '              AnimateWindowFlags.AW_BLEND _
            '              Or AnimateWindowFlags.AW_VER_POSITIVE _
            '              Or AnimateWindowFlags.AW_SLIDE)
            AnimateWindow(frmToAnimate.Handle, 500, _
                          AnimateWindowFlags.AW_VER_POSITIVE _
                          Or AnimateWindowFlags.AW_SLIDE)
        Else
            AnimateWindow(frmToAnimate.Handle, 500, AnimateWindowFlags.AW_VER_NEGATIVE Or AnimateWindowFlags.AW_HIDE)
        End If

    End Sub

    Public Sub CopyTo(ByVal source As Object, ByVal dest As Object)
        Dim type1 As System.Type = source.[GetType]()
        Dim type2 As System.Type = dest.[GetType]()
        For Each pInfo1 As PropertyInfo In type1.GetProperties()
            For Each pInfo2 As PropertyInfo In type2.GetProperties()
                If pInfo1.Name = pInfo2.Name Then
                    If pInfo1.CanRead AndAlso pInfo2.CanWrite Then
                        pInfo2.SetValue(dest, pInfo1.GetValue(source, Nothing), Nothing)
                    End If
                    Exit For
                End If
            Next
        Next
    End Sub

 
    Public Function GetSafeStyleForFontFamily(ByVal fnt As Font, _
                                              ByVal style As FontStyle) As FontStyle

        'http://www.devx.com/vb2themax/Tip/19392
        ' Example:
        '   GetSafeStyleForFontFamily(richTextBox1.SelectionFont.FontFamily,
        '  '     richTextBox1.SelectionFont.Style)

        ' Create a FontFamily object.
        Dim fontFam As FontFamily = fnt.FontFamily

        ' remove the styles not supported
        If (style And FontStyle.Regular) = FontStyle.Regular Then
            ' if the regular style is currently present, but not supported 
            ' by the new font family, remove it
            If Not fontFam.IsStyleAvailable(FontStyle.Regular) Then
                style = style And Not FontStyle.Regular
            End If
        End If
        ' do the same for bold, italic and underline
        If (style And FontStyle.Bold) = FontStyle.Bold Then
            If Not fontFam.IsStyleAvailable(FontStyle.Bold) Then
                style = style And Not FontStyle.Bold
            End If
        End If
        If (style And FontStyle.Italic) = FontStyle.Italic Then
            If Not fontFam.IsStyleAvailable(FontStyle.Italic) Then
                style = style And Not FontStyle.Italic
            End If
        End If
        If (style And FontStyle.Underline) = FontStyle.Underline Then
            If Not fontFam.IsStyleAvailable(FontStyle.Underline) Then
                style = style And Not FontStyle.Underline
            End If
        End If
        If (style And FontStyle.Strikeout) = FontStyle.Strikeout Then
            If Not fontFam.IsStyleAvailable(FontStyle.Strikeout) Then
                style = style And Not FontStyle.Strikeout
            End If
        End If
        Return style
    End Function

    Public Function GetEnumValue(ByVal myEnum As System.Enum) As Integer
        Return DirectCast([Enum].Parse(myEnum.GetType(), myEnum.ToString()), Integer)
    End Function

End Module

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
tix
Italy Italy
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions