DSAPI WIN7风格

Posted DYLIKE

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了DSAPI WIN7风格相关的知识,希望对你有一定的参考价值。

在Winform项目中,有时需要将UI变成适应Vista/Windows7/8/10的风格,通过"选用"以下代码来使你的UI支持系统主题渲染.

注:该功能不支持XP,建议使用DS控件库中的WIN7风格控件。

新建工程,添加相关控件,复制粘贴以下代码即可

Public Class Form1
 
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        DSAPI.Win7特性.任务栏特效.设置任务栏进度(Me.Handle, 50, 100)
        \'*******缩略图按钮标识ID至少应200以上,以避免系统冲突
        \'------------------
        Dim Itm1 As New DSAPI.Win7特性.任务栏缩略图.缩略图控制按钮
        With Itm1
            .标记 = DSAPI.Win7特性.任务栏缩略图.缩略图按钮状态.启用
            .标识ID = 500
            .标志组合 = DSAPI.Win7特性.任务栏缩略图.缩略图按钮标志.提示 + DSAPI.Win7特性.任务栏缩略图.缩略图按钮标志.图标 + DSAPI.Win7特性.任务栏缩略图.缩略图按钮标志.标记
            .图标 = My.Resources.D__32_.GetHicon
            .提示 = "上一首"
        End With
        \'------------------
        Dim Itm2 As New DSAPI.Win7特性.任务栏缩略图.缩略图控制按钮
        With Itm2
            .标记 = DSAPI.Win7特性.任务栏缩略图.缩略图按钮状态.启用
            .标识ID = 501
            .标志组合 = DSAPI.Win7特性.任务栏缩略图.缩略图按钮标志.提示 + DSAPI.Win7特性.任务栏缩略图.缩略图按钮标志.图标 + DSAPI.Win7特性.任务栏缩略图.缩略图按钮标志.标记
            .图标 = My.Resources.D__41_.GetHicon
            .提示 = "暂停"
        End With
        \'------------------
        Dim Itm3 As New DSAPI.Win7特性.任务栏缩略图.缩略图控制按钮
        With Itm3
            .标记 = DSAPI.Win7特性.任务栏缩略图.缩略图按钮状态.启用
            .标识ID = 502
            .标志组合 = DSAPI.Win7特性.任务栏缩略图.缩略图按钮标志.提示 + DSAPI.Win7特性.任务栏缩略图.缩略图按钮标志.图标 + DSAPI.Win7特性.任务栏缩略图.缩略图按钮标志.标记
            .图标 = My.Resources.D__31_.GetHicon
            .提示 = "播放"
        End With
        \'------------------
        Dim Itm4 As New DSAPI.Win7特性.任务栏缩略图.缩略图控制按钮
        With Itm4
            .标记 = DSAPI.Win7特性.任务栏缩略图.缩略图按钮状态.启用
            .标识ID = 503
            .标志组合 = DSAPI.Win7特性.任务栏缩略图.缩略图按钮标志.提示 + DSAPI.Win7特性.任务栏缩略图.缩略图按钮标志.图标 + DSAPI.Win7特性.任务栏缩略图.缩略图按钮标志.标记
            .图标 = Me.Icon.ToBitmap.GetHicon
            .提示 = "帮助"
        End With
        DSAPI.Win7特性.任务栏特效.添加缩略图控制按钮(Me.Handle, New DSAPI.Win7特性.任务栏缩略图.缩略图控制按钮() {Itm1, Itm2, Itm3, Itm4})
        AddHandler DSAPI.Win7特性.任务栏特效.缩略图按钮被点击, AddressOf ItmClick
    End Sub
 
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        DSAPI.Win7特性.任务栏特效.初始化(Me)
        DSAPI.控件相关.Form窗体.窗体支持鼠标拖动(Me, True)
        Me.ForeColor = Color.FromArgb(255, 2, 2, 2)
        For Each S As String In [Enum].GetNames(ListView1.View.GetType)
            ComboBox1.Items.Add(S)
        Next
        ComboBox1.SelectedIndex = 0
        For Each S As String In [Enum].GetNames(GetType(DSAPI.Win7特性.任务栏缩略图.任务栏进度条状态))
            ComboBox2.Items.Add(S)
        Next
        ComboBox2.SelectedIndex = 0
    End Sub
    Sub ItmClick(ID As Integer)
        Select Case ID
            Case 500
                MsgBox("点击了上一首")
            Case 501
                MsgBox("点击了暂停")
            Case 502
                MsgBox("点击了播放")
            Case 503
                MsgBox("点击了帮助")
        End Select
    End Sub
 
    Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown
        TreeView1.ExpandAll()
    End Sub
 
    Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
        ListView1.View = ComboBox1.SelectedIndex
    End Sub
 
    Private Sub LinkLabel1_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
        Try
            Process.Start("SystemPropertiesAdvanced.exe")
        Catch 
        End Try
    End Sub
 
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        If Form2.Visible = True Then Exit Sub
        Form2.Show()
        DSAPI.Win7特性.在指定窗体指定区域显示源窗体缩略图(Form2.Handle, New Rectangle(0, 0, Me.Width, Me.Height), Me.Handle, False, 255)
    End Sub
 
    Private Sub TrackBar1_Scroll(sender As Object, e As EventArgs) Handles TrackBar1.Scroll
    End Sub
 
    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        DSAPI.Win7特性.设置窗体为磨砂透明效果(Me)
    End Sub
 
    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        DSAPI.Win7特性.使控件应用Win7资源管理器风格(Me)
    End Sub
 
    Private Sub TrackBar1_ValueChanged(sender As Object, e As EventArgs) Handles TrackBar1.ValueChanged
        DSAPI.Win7特性.任务栏特效.设置任务栏进度(Me.Handle, TrackBar1.Value, TrackBar1.Maximum)
 
    End Sub
 
    Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox2.SelectedIndexChanged
        DSAPI.Win7特性.任务栏特效.设置任务栏进度条状态(Me.Handle, GetV(ComboBox2.SelectedItem.ToString))
    End Sub
    Private Function GetV(S As String) As Integer
        Dim Ints() As Integer = [Enum].GetValues(GetType(DSAPI.Win7特性.任务栏缩略图.任务栏进度条状态))
        For Each T As Integer In Ints
            If [Enum].GetName(GetType(DSAPI.Win7特性.任务栏缩略图.任务栏进度条状态), T) = S Then
                Return T
            End If
        Next
        Return 0
    End Function
End Class

  

以上是关于DSAPI WIN7风格的主要内容,如果未能解决你的问题,请参考以下文章

DSAPI 短域名服务

DSAPI 图形图像篇(上)

DSAPI CMD命令行进程代理

DSAPI多功能组件编程应用-DS提示气泡

DSAPI.网络.网卡信息属性表

DSAPI+DS????????? Windows7??????????????????