大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> NET专区 -> 自定义控件--xp风格按钮(可设置文字颜色)

自定义控件--xp风格按钮(可设置文字颜色)

时间: 2021-07-31 作者:daque

 imports system.drawing

imports system.componentmodel

public class winxpbutton

    inherits system.windows.forms.button

 

 

    private my_mousedown as boolean = false '鼠标按下

    private my_mousehover as boolean = false '鼠标移到上面

    private m_textcolor as color = system.drawing.color.black '字体神色

    <description("字体神色。")> _

    public property textcolor() as color

        get

            return m_textcolor

        end get

        set(byval value as color)

            m_textcolor = value

            me.invalidate()

        end set

    end property

    public sub new()

        mybase.new()

 

 

        '该调用是 windows 窗体安置器所必然的。

        initializecomponent()

 

 

        '在 initializecomponent() 调用之后填补任何初始化,true表露将指定的格局应用到控件

 

 

        '竖立控件格局位无妨充斥地变化控件举措

        me.setstyle(controlstyles.userpaint, true)

        '联系事故萎任

        addhandler me.mousedown, addressof my_onmousedown

        addhandler me.mouseup, addressof my_onmouseup

        addhandler me.mouseenter, addressof my_onmouseenter

      

        addhandler me.mouseleave, addressof my_onmouseleave

        height = 23        

width = 75

    end sub

 

 

    protected overrides sub onpaint(byval pevent as system.windows.forms.painteventargs)

        'pevent.cliprectangle指在其中绘制的矩形,即应用父控件的背场合来画这个矩形按钮

        pevent.graphics.fillrectangle(new solidbrush(me.parent.backcolor), pevent.cliprectangle)

        if (enabled = false) then

            '画不行用情景

            drawdisablebutton(pevent.graphics)

        elseif (my_mousedown) then '画鼠标按下情景

            drawmousedownbutton(pevent.graphics)

        elseif (my_mousehover) then '画鼠标移动到其上情景

            drawmousehoverbutton(pevent.graphics)

        elseif (focused) then '有重心,但鼠标未移动到其上

            drawcontainfocusbutton(pevent.graphics)

        else '一致局面下

            drawnormalbutton(pevent.graphics)

        end if

        '写文本

        writetext(pevent.graphics)

    end sub

    '鼠标按下的情景处治

    private sub my_onmousedown(byval sender as object, byval e as mouseeventargs)

        my_mousedown = true '鼠标按下

    end sub

    '鼠标松开情景的处治

    private sub my_onmouseup(byval sender as object, byval e as mouseeventargs)

        my_mousedown = false '鼠标松开

        '从新绘制控件时暴发 paint 事故。painteventargs 指定绘制控件所用的 graphics

        '以及绘制控件场合的 cliprectangle。

        dim pe as painteventargs = new painteventargs(creategraphics(), clientrectangle)

        onpaint(pe)

    end sub

    '鼠标介入

    private sub my_onmouseenter(byval sender as object, byval e as eventargs)

        my_mousehover = true '鼠标移动到其上

        '

        dim pe as painteventargs = new painteventargs(creategraphics(), clientrectangle)

        onpaint(pe)

    end sub

    '鼠标移动开

    private sub my_onmouseleave(byval sender as object, byval e as eventargs)

        my_mousehover = false '鼠标移动开

        '

        dim pe as painteventargs = new painteventargs(creategraphics(), clientrectangle)

        onpaint(pe)

    end sub

 

 

    private sub drawborder(byval g as graphics, byval state as integer)

        if (state = 1) then '绘制一致边框

            '绘制一个画笔,高光点,宽窄2

            dim p as pen = new pen(systemcolors.controllightlight, 2)

            'g.drawline画线,p是画笔,背后是第一个点的坐标,第二个点的坐标

            g.drawline(p, 1, 1, 1, height - 2) '绘制左侧竖线

            g.drawline(p, 1, 1, width - 2, 1) '绘制上面横线

            g.drawline(p, width - 1, 2, width - 1, height - 2) '绘制右侧竖线,由于保持在上面绘制了横线(横坐标为1),以是从2发源

            g.drawline(p, 2, height - 1, width - 2, height - 1) '绘制下面横线

        elseif (state = 2) then '绘制移动到其上的边框

            '与一致边框用高光辩别的是表白黄色

            dim p as pen = new pen(color.yellow, 2)

            g.drawline(p, 1, 1, 1, height - 2)

            g.drawline(p, 1, 1, width - 2, 1)

            g.drawline(p, width - 1, 2, width - 1, height - 2)

            g.drawline(p, 2, height - 1, width - 2, height - 1)

 

 

        elseif (state = 3) then '绘制按下的表白边框

            '与一致边框用高光辩别的是表白暗褐色

            dim p as pen = new pen(systemcolors.controldark, 2)

            g.drawline(p, 1, 1, 1, height - 2)

            g.drawline(p, 1, 1, width - 2, 1)

            g.drawline(p, width - 1, 2, width - 1, height - 2)

            g.drawline(p, 2, height - 1, width - 2, height - 1)

 

 

        elseif (state = 4) then '绘制不行用情景边框

            '与一致边框用高光辩别的是表白亮色

            dim p as pen = new pen(systemcolors.controllight, 2)

            g.drawline(p, 1, 1, 1, height - 2)

            g.drawline(p, 1, 1, width - 2, 1)

            g.drawline(p, width - 1, 2, width - 1, height - 2)

            g.drawline(p, 2, height - 1, width - 2, height - 1)

 

 

        elseif (state = 5) then '绘制有重心但鼠标不在其上的情景

            '与一致边框用高光辩别的是表白兰色

            dim p as pen = new pen(color.skyblue, 2)

            g.drawline(p, 1, 1, 1, height - 2)

            g.drawline(p, 1, 1, width - 2, 1)

            g.drawline(p, width - 1, 2, width - 1, height - 2)

            g.drawline(p, 2, height - 1, width - 2, height - 1)

        end if

        '//做完如上的处治后再对可用和不行用做圆化边沿处治(也即是把按钮的4个角进行圆化处治)

        if (state = 4) then '不行用时

            '应用画笔,color.fromargb(161, 161, 146)是从一个32位的argb值创作体制神色,宽窄为1

            dim p as pen = new pen(color.fromargb(161, 161, 146), 1)

            g.drawline(p, 0, 2, 0, height - 3) '左侧竖线(取消两个边角剩下的线)

            g.drawline(p, 2, 0, width - 3, 0) '上面横线(取消两个边角剩下的线)

            g.drawline(p, width - 1, 2, width - 1, height - 3) '右侧竖线(取消两个边角剩下的线)

            g.drawline(p, 2, height - 1, width - 3, height - 1) '下面的横线

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.