asp教程.net winform的 listview控件
using system.collections.generic;
using system.drawing;
using system.windows.forms;namespace qiqi.windows.forms
{
public class qiqilistbox : control
{
private readonly list_items;
private color _border_color;
private int _item_height;private color _selected_back_color;
private int _selected_index;public qiqilistbox()
{
setstyle(controlstyles.userpaint | controlstyles.allpaintinginwmpaint, true);
_items = new list();
_item_;
_selected_index = -1;
_border_color = color.fromargb(245, 170, 114);
_selected_back_color = color.fromargb(255, 237, 209);
}public color bordercolor
{
get { return _border_color; }
set { _border_color = value; }
}public color selectedbackcolor
{
get { return _selected_back_color; }
set { _selected_back_color = value; }
}public int selectedindex
{
get { return _selected_index; }
set { _selected_index = value; }
}public int itemheight
{
get { return _item_height; }
set { _item_height = value; }
}public void insert_item(qiqilistboxitem item, int index)
{
_items.insert(index, item);
}public void delete_item(int index)
{
_items.removeat(index);
}protected override void onpaintbackground(painteventargs pevent)
{
base.onpaintbackground(pevent);
//边框
using (var pen = new pen(_border_color))
{
rectangle rect = displayrectangle;
rect.width -= 1;
rect.height -= 1;
pevent.graphics.drawrectangle(pen, rect);
}
}protected override void onpaint(painteventargs e)
{
for (int i = 0; i < _items.count; i++)
{
draw_item(e.graphics, i, i == _selected_index);
}
}private void draw_item(graphics g, int index, bool selected)
{
qiqilistboxitem item = _items[index];
rectangle rect = get_item_rect(index);
using (brush bru = new solidbrush(selected ? _selected_back_color : backcolor))
{
g.fillrectangle(bru, rect);
}
//图标
g.drawimage(item.image, 1, 1 + index*_item_height, 24, 24);
rectangle rect_text = rect;
rect_text.width -= 24;
rect_text.x += 24 + 10;
var sf = new stringformat();
sf.linealignment = stringalignment.center;
g.drawstring(item.text, font, brushes.black, rect_text, sf);
}private rectangle get_item_rect(int index)
{
return new rectangle(2, index*_item_height + 2, width - 4, _item_height);
}public int hit_test(int x, int y)
{
for (int i = 0; i < _items.count; i++)
{
if (get_item_rect(i).contains(x, y))
return i;
}
return -1;
}protected override void onmousedown(mouseeventargs e)
{
base.onmousedown(e);
int index = hit_test(e.x, e.y);
graphics g = creategraphics();
if (_selected_index != -1)
draw_item(g, _selected_index, false);
if (index != -1)
{
_selected_index = index;
draw_item(g, index, true);
}
}
}public class qiqilistboxitem
{
public image image { get; set; }
public string text { get; set; }
public object tag { get; set; }
}
}
//调用方法
list.insert_item(new qiqilistboxitem
{
image = image.fromfile(@"f:tempi1.png"),
text = "智能秘书",
}, 0);
list.insert_item(new qiqilistboxitem
{
image = image.fromfile(@"f:tempi2.png"),
text = "信息订阅",
}, 0);
list.insert_item(new qiqilistboxitem
{
image = image.fromfile(@"f:tempi3.png"),
text = "空间信息",
}, 0);
list.invalidate();
创造与魔法 安卓版v1.0.0750
创造与魔法是一款开放世界手游,在游戏中玩家可探索这个奇妙的世
创造与魔法修改版 最新版v1.0.0750
创造与魔法无限点券版是款探索冒险游戏,该款游戏的操作还是蛮自
战争与文明官方版本 安卓版v1.7.16
战争与文明是一款由上海邮通科技有限公司开发的战争策略游戏,这
迷你世界0元领皮肤无限迷你币版 最新安卓版v1.43.0
迷你世界0元购买皮肤版是这款开放沙盒冒险建造游戏的特殊破解版
创造与魔法无限经验版 安卓版v1.0.0750
创造与魔法无限经验版是款可以改造环境,整个游戏的自由度还是蛮