大雀软件园

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

自定义控件--图片按钮

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

 图片按钮:

思路:很大概,即是在一个picturebox控件上安排一个button控件,尔后将这个button填补进picturebox上(保护先拖拽picturebox,后拖拽button),竖立这个button的背场合(这个工夫是对抗于picturebox)为透明。

 

imports system.componentmodel

public class picturebutton

    inherits system.windows.forms.usercontrol

 

#region " windows 窗体安置器天才的代码 "

 

    'usercontrol 重写 dispose 以整治组件列表。

    protected overloads overrides sub dispose(byval disposing as boolean)

        if disposing then

            if not (components is nothing) then

                components.dispose()

            end if

        end if

        mybase.dispose(disposing)

    end sub

 

    'windows 窗体安置器所必然的

    private components as system.componentmodel.icontainer

 

    '堤防:以次过程是 windows 窗体安置器所必然的

    '无妨应用 windows 窗体安置器篡改此过程。

    '不要应用代码编辑器篡改它。

    friend withevents picturebox1 as system.windows.forms.picturebox

    friend withevents button1 as system.windows.forms.button

    <system.diagnostics.debuggerstepthrough()> private sub initializecomponent()

        me.picturebox1 = new system.windows.forms.picturebox()

        me.button1 = new system.windows.forms.button()

        me.suspendlayout()

        '

        'picturebox1

        '

        me.picturebox1.name = "picturebox1"

        me.picturebox1.size = new system.drawing.size(136, 40)

        me.picturebox1.tabindex = 0

        me.picturebox1.tabstop = false

        '

        'button1

        '

        me.button1.name = "button1"

        me.button1.tabindex = 1

        me.button1.text = "button1"

        '

        'picturebutton

        '

        me.controls.addrange(new system.windows.forms.control() {me.button1, me.picturebox1})

        me.name = "picturebutton"

        me.resumelayout(false)

 

    end sub

 

#end region

    public sub new()

        mybase.new()

 

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

        initializecomponent()

 

        '在 initializecomponent() 调用之后填补任何初始化

        me.button1.width = 100 ‘竖立按钮的初始大小

        me.button1.height = 23

      

 

        me.button1.backcolor = color.transparent ‘背场合透明

        me.button1.forecolor = color.black

        me.picturebox1.controls.add(me.button1)

    end sub

    private m_text as string ‘竖立按钮标题

    private a as integer

 

    'private m_image as image

    <description("picturebox图片。")> _

    public property image() as image

        get

            return me.picturebox1.image

        end get

        set(byval value as image)

            me.picturebox1.image = value

            invalidate()

        end set

    end property

 

    shadows property forecolor() as color

        get

            return me.button1.forecolor

        end get

        set(byval value as color)

            me.button1.forecolor = value

            invalidate()

        end set

    end property

    shadows sub resetforecolor()

        me.button1.forecolor = systemcolors.controltext

    end sub

    '////

    '按钮的单击事故

    event btnclick(byval sender as object, byval e as system.eventargs)

 

    private sub button1_click(byval sender as object, byval e as system.eventargs) handles button1.click

        raiseevent btnclick(me, e)

    end sub

    '////

 

    '控件变幻大小时,需重绘控件,以使子控件排位场合

    private sub filetextbox_resize(byval sender as object, byval e as system.eventargs) handles mybase.resize

        redrawcontrols()

    end sub

 

    '子控件会灵活贯穿容器的font属性,以是变幻容器的font属性时也要重绘控件

    protected overrides sub onfontchanged(byval e as system.eventargs)

        '让基控件变革文本框

        mybase.onfontchanged(e)

        '重绘控件

        redrawcontrols()

    end sub

 

    '重绘控件

    private sub redrawcontrols()

        '控件宽窄

        dim width as integer = me.clientrectangle.width '博得处世区宽

        '以按钮的莫斯科大学来确定控件莫斯科大学

        dim btnside as integer = button1.height

        dim btnwidth as integer = button1.width

        if me.clientrectangle.height <> btnside then

            '竖立控件处世区的大小

            'me.setclientsizecore(btnwidth, btnside)

            me.setclientsizecore(width, btnside) '这边运用途事区的宽是因为:按钮和picturebox无妨安置宽窄

            '上面的语句鼓励了嵌套的resize事故,以是需要顿时退出,纵然不退出,就会反复调用介入死循环

            exit sub

        end if

 

        '安置子控件的大小

        'txt.setbounds(0, 0, width, btnside)

        'btn.setbounds(width - 19, 2, 17, btnside - 4)

 

        me.picturebox1.setbounds(0, 0, width, btnside)

        me.picturebox1.sizemode = pictureboxsizemode.stretchimage

        me.button1.setbounds(0, 0, width, btnside)

 

    end sub

end class

热门阅览

最新排行

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