private sub filllistboxwithcolors()
me.listbox1.drawmode = drawmode.ownerdrawfixed
me.listbox1.itemheight = 24
'避免閃爍
me.listbox1.beginupdate()
listbox1.items.clear()
dim pi as reflection.propertyinfo
for each pi in gettype(color).getproperties(reflection.bindingflags.public or reflection.bindingflags.static)
me.listbox1.items.add(pi.name)
next
listbox1.endupdate()
end sub
private sub listbox1_drawitem(byval sender as object, byval e as system.windows.forms.drawitemeventargs) handles listbox1.drawitem
dim rect as rectangle = e.bounds '每一項的邊框
if e.state and drawitemstate.selected then
e.graphics.fillrectangle(systembrushes.window, rect)
end if
dim colorname as string = listbox1.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.listbox1.font, b2, rect.x, rect.y)
end sub
ListBox控制項
呈現形態 1 糖醋排骨 2 紅燒雞塊 3 清蒸鮑魚 4 酸菜魚 5 香辣雞翅 select 控制項語句 1 糖醋排骨 2 紅燒雞塊 3 清蒸鮑魚 4 酸菜魚 listbox可多選 可呼叫屬性與dropdownlist相同 ibox selectindex 只返回乙個數值 0,1,2,3 ibox s...
ListBox控制項的操作
items的相關使用方法 1 往listbox中新增乙個資料 listbox.items.add 資料1 2 往listbox中新增多個資料集合 string list new string listbox.items.addrange list 3 在listbox指定位置插入乙個新值 listb...
ASP Web控制項 ListBox
樣板 asp listboxid listbox1 runat server height 20px width 73px asp listitem selected true value 1 第一項 asp listitem asp listitem value 2 第二項 asp listite...