Top / JUNK / VisualStyleRenderer

Option Strict On

Imports System.Windows.Forms.VisualStyles

Public Class Form1

    Private Enum ComboBoxParts As Integer
        CP_DROPDOWNBUTTON = 1
        CP_BACKGROUND = 2
        CP_TRANSPARENTBACKGROUND = 3
        CP_BORDER = 4
        CP_READONLY = 5
        CP_DROPDOWNBUTTONRIGHT = 6
        CP_DROPDOWNBUTTONLEFT = 7
        CP_CUEBANNER = 8
    End Enum

    Protected Overrides Sub OnPaint(e As PaintEventArgs)
        MyBase.OnPaint(e)
        If VisualStyleRenderer.IsSupported Then
            For Each part As ComboBoxParts In [Enum].GetValues(GetType(ComboBoxParts))
                e.Graphics.DrawString(String.Format("{0}", part),
                                    Me.Font, SystemBrushes.WindowText, New Point(10, part * 20))
                For Each state As ComboBoxState In System.Enum.GetValues(GetType(ComboBoxState))
                    Dim rect As New Rectangle(state * 20 + 250, part * 20, 16, 16)
                    DrawElement(e.Graphics, rect, "COMBOBOX", part, state)
                Next
            Next
        End If

    End Sub

    <ThreadStatic>
    Private Shared VsRenderer As VisualStyleRenderer = Nothing

    Private Sub DrawElement(g As Graphics, rect As Rectangle, className As String, part As Integer, state As ComboBoxState)
        Dim element As VisualStyleElement = VisualStyleElement.CreateElement(className, part, state)
        If VisualStyleRenderer.IsElementDefined(element) Then
            If VsRenderer Is Nothing Then
                VsRenderer = New VisualStyleRenderer(element)
            Else
                VsRenderer.SetParameters(element)
            End If
            VsRenderer.DrawParentBackground(g, rect, Me)
            VsRenderer.DrawBackground(g, rect)
        Else
            g.FillRectangle(Brushes.Gray, rect)
        End If
    End Sub

End Class
VisualStyleRenderer.png



トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   最終更新のRSS
Last-modified: 2020-01-21 (火) 09:15:49 (126d)