欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

DSAPI WIN7风格

程序员文章站 2023-10-19 17:51:11
在Winform项目中,有时需要将UI变成适应Vista/Windows7/8/10的风格,通过"选用"以下代码来使你的UI支持系统主题渲染. 注:该功能不支持XP,建议使用DS控件库中的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 WIN7风格DSAPI WIN7风格DSAPI WIN7风格DSAPI WIN7风格DSAPI WIN7风格