如何使用C#在列表视图控件中为项目添加边框? [英] How to add border to items in a listview control using C#?

查看:142
本文介绍了如何使用C#在列表视图控件中为项目添加边框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是listview控件,其中通过ImageList添加图像

I am using a listview control where I am adding Images through ImageList

if (dtPhoto.Rows.Count > 0)
{
foreach (DataRow dr in dtPhoto.Rows)
            {
                if (dr["Photo"].ToString() != "")
                {
                    byte[] barrImg = (byte[])dr["Photo"];
                    MemoryStream mStream = new MemoryStream(barrImg);
                    imageList.Images.Add(Image.FromStream(mStream));
                }
            }
        }

        imageList.ImageSize = new Size(75, 75);
        lvItem.LargeImageList = imageList;

        for (int i = 0; i < imageList.Images.Count; i++)
        {
            lvItem.Items.Add(dtPhoto.Rows[i]["Name"].ToString() + "\n" + "(" + dtPhoto.Rows[i]["Type"].ToString() + ")", i);
        }

我想为Listview中的每个项目添加边框吗? 请帮忙. 预先感谢.

I want to add border to each item in the Listview Is it possible? Please Help. Thanks in advance.

推荐答案

您可以将ListView的OwnerDraw属性设置为true,然后处理DrawItem事件并绘制边框,例如:

You can set OwnerDraw property of ListView to true, then handle DrawItem event and draw the border, for example:

private void listView1_DrawItem(object sender, DrawListViewItemEventArgs e)
{
    e.DrawDefault = true;
    e.Graphics.DrawRectangle(Pens.Red, e.Bounds);
}

这篇关于如何使用C#在列表视图控件中为项目添加边框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆