国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

自定義控件--圖片按鈕

2024-07-21 02:24:17
字體:
來源:轉載
供稿:網友
圖片按鈕:

思路:很簡單,就是在一個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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 清水河县| 九龙坡区| 邯郸市| 九龙城区| 宜宾市| 海城市| 深水埗区| 台前县| 长岭县| 博爱县| 石嘴山市| 扬州市| 邳州市| 连江县| 陈巴尔虎旗| 平定县| 彭山县| 松滋市| 七台河市| 扶风县| 天长市| 绥化市| 革吉县| 嘉定区| 江川县| 恭城| 南靖县| 贞丰县| 皮山县| 宜兰市| 游戏| 兴海县| 永靖县| 富锦市| 乌拉特后旗| 凌源市| 西乡县| 壶关县| 巴林左旗| 颍上县| 黑河市|