在.NET列表视图项剪裁风格? [英] listview item cut style in .NET?

查看:119
本文介绍了在.NET列表视图项剪裁风格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何实现LVIS_CUT风格的ListView项等价?它看起来像它不是由框架暴露?如果我的P / Invoke?

How do I achieve the equivalent of the LVIS_CUT style for a listview item? It looks like it's not exposed by the framework? Should I P/Invoke?

编辑:LVIS_CUT是影响该项目的外观一个Win32风格:它在为灰色图像的项目。你可以看到它在Windows资源管理器操作:选择一个文件,按下Ctrl + X

LVIS_CUT is a Win32 style that affects the look of the item: It grays the item image. You can see it in action in Windows Explorer: Select a file and type Ctrl+X.

TIA。

推荐答案

好吧,实现LVIS_CUT风格,相当于一种方法是以下内容:

Well, one way to "achieve the equivalent of the LVIS_CUT style" would be the following:

沿线的使用功能

private void MakeCutList(ImageList sourceList, Color background)
{
   Brush overlay = new SolidBrush(Color.FromArgb(128, BackColor));
   Rectangle rect = new Rectangle(new Point(0, 0), sourceList.ImageSize);

   foreach (Image img in sourceList.Images)
   {
      Bitmap cutBmp = new Bitmap(img.Width, img.Height);

      using (Graphics g = Graphics.FromImage(cutBmp))
      {
         g.DrawImage(img, 0, 0);
         g.FillRectangle(overlay, rect);
      }

      sourceList.Images.Add(cutBmp);    
   }
}

把你的ListView(即listView1.ImageList)所使用的图像列表和添加的所有图标的腰斩的版本。你可以在你的形式的InitializeComponent后,立即调用此方法,如

to take the image list used by your ListView (i.e. listView1.ImageList) and add the "cut" versions of all the icons. You might call this immediately after InitializeComponent in your form, like

public Form1()
{
    InitializeComponent();
    MakeCutList(listView1.LargeImageList, listView1.BackColor);
}

然后就可以使用code这样的

Then you could use code like this

private void SetCutState(ListViewItem lvi, Boolean isItemCut)
{
    int originalListSize = lvi.ImageList.Images.Count / 2;
    int baseIndex = lvi.ImageIndex % originalListSize;
    int cutImagesOffset = originalListSize;

    if (isItemCut)
    {
        lvi.ImageIndex = cutImagesOffset + baseIndex;
        lvi.ForeColor = SystemColors.GrayText;
    }
    else
    {
        lvi.ImageIndex = baseIndex;
        lvi.ForeColor = SystemColors.WindowText;
    }
}

到一个项目的状态改变到被切割或没有。

to change the state of an item to being cut or not.

一旦你得到工作,你可以尝试把类似code到ListView控件的子类的版本。

Once you get that working, you could try to put similar code into a subclassed version of the ListView control.

这篇关于在.NET列表视图项剪裁风格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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