国产探花免费观看_亚洲丰满少妇自慰呻吟_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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 十堰市| 江门市| 婺源县| 昭通市| 深州市| 沙洋县| 湛江市| 广宁县| 遵义市| 东至县| 湖北省| 日照市| 苍溪县| 潼关县| 梁平县| 东方市| 岳阳县| 邓州市| 衢州市| 盐池县| 汨罗市| 万全县| 道孚县| 肇东市| 金阳县| 博野县| 泉州市| 玉山县| 衡阳县| 尼木县| 罗江县| 阳春市| 永登县| 射洪县| 岱山县| 修文县| 边坝县| 富川| 苍山县| 永德县| 滕州市|