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

首頁 > 編程 > .NET > 正文

顏色下拉COMBOBOX控件(vb.net)

2024-07-10 13:00:39
字體:
來源:轉載
供稿:網友
中國最大的web開發資源網站及技術社區,
 

前不久,有位朋友發帖,尋求顏色選擇的combobox  的制作方法,經過試驗,整理了出來,僅供參考。

(注:如有引用,請注明出處和作者)

                                                                                                                                 --閔峰(2005/08/06東莞)

 private sub filllistboxwithcolors()
        me.combobox1.drawmode = drawmode.ownerdrawfixed
        me.combobox1.dropdownstyle = comboboxstyle.dropdownlist
        me.combobox1.itemheight = 15
        '避免閃爍beginupdate
        me.combobox1.beginupdate()
        combobox1.items.clear()
        dim pi as reflection.propertyinfo
        for each pi in gettype(color).getproperties(reflection.bindingflags.public or reflection.bindingflags.static)
            me.combobox1.items.add(pi.name)
        next
        combobox1.endupdate()

    end sub

 private sub combobox1_drawitem(byval sender as object, byval e as system.windows.forms.drawitemeventargs) handles combobox1.drawitem
        if e.index < 0 then exit sub
      
        dim rect as rectangle = e.bounds '每一項的邊框
      
        '繪制項如果被選中則顯示高亮顯示背景,否則用白色
        if e.state and drawitemstate.selected then
            e.graphics.fillrectangle(systembrushes.highlight, rect)
        else
            e.graphics.fillrectangle(systembrushes.window, rect)
        end if

        dim colorname as string = combobox1.items(e.index)
        dim b as new solidbrush(color.fromname(colorname))

        '縮小選定項區域()
        rect.inflate(-16, -2)
        '填充顏色(文字對應的顏色)
        e.graphics.fillrectangle(b, rect)
        '繪制邊框()
        e.graphics.drawrectangle(pens.black, rect)
        dim b2 as brush
        '確定顯示的文字的顏色()
        if cint(b.color.r) + cint(b.color.g) + cint(b.color.b) > 128 * 3 then
            b2 = brushes.black
        else
            b2 = brushes.white

        end if
        e.graphics.drawstring(colorname, me.combobox1.font, b2, rect.x, rect.y)

    end sub

    private sub form1_load(byval sender as system.object, byval e as system.eventargs) handles mybase.load
        filllistboxwithcolors()
    end sub

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 莒南县| 内江市| 武冈市| 新巴尔虎右旗| 宣威市| 玉田县| 木兰县| 蓝山县| 郯城县| 绥滨县| 巴南区| 澎湖县| 龙州县| 敦化市| 九寨沟县| 龙川县| 宜宾县| 巴林左旗| 曲阳县| 长武县| 邵阳市| 都安| 宜都市| 涡阳县| 娱乐| 中山市| 柳河县| 杂多县| 巴塘县| 韩城市| 西藏| 靖江市| 许昌县| 乡城县| 临桂县| 揭阳市| 辽源市| 博爱县| 阿荣旗| 仁寿县| 吉隆县|