(ListView的?) - 控制就像在Windows资源管理器 [英] (ListView?)-Control like in Windows Explorer

查看:209
本文介绍了(ListView的?) - 控制就像在Windows资源管理器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道是否有什么办法,使像一个在Windows资源管理器的自动启动控制,当你插件的设备。

I'm wondering if there is any way to make a control like that one in windows explorer's auto start when you plugin a device.

我曾认为这可能是一个ListView控制在或多或少的改进途径,但我没能找到与谷歌任何东西。我也查了很多$ C $的CProject的页面。

I had thought that this could be a listview-control in a more or less modified way, but I was not able to find anything with Google. I also checked many CodeProject-pages.

有没有人有一个想法,我会在哪里能得到控制或者我怎么能让一个自己? (我并不好与的OwnerDraw:P)

Does anyone have an idea where I would be able to get the control or how I could make one myself? (I am not that good with OwnerDraw :P)

感谢。

推荐答案

其实扭捏一个的ListView 并不比ownerDrawing容易。下面的例子说明,它确实是多么简单的一个例子。

Actually tweaking a ListView is not any easier than ownerDrawing it. Here is an example that shows, how simple it really is.

您只需脚本一个事件( DRAWITEM )和你做。

You just script one event (DrawItem) and you are done.

这件code的假设:


  • 的LV的视图设置为列表

  • 您有一个合适的ImageList添加到窗体

  • 您有LV的的OwnerDraw设为true

  • 您已经添加了两列持有两个标签显示的文本

  • 您所做的第一列宽度足以容纳整个的东西,被抽

  • 您已经取得了LV的字号一样大的图像的身高(说32)

  • 分配适当的ImageIndex值到LV的项目

private void listView1_DrawItem(object sender, DrawListViewItemEventArgs e)
{
  Point point0 = new Point(e.Bounds.Left, e.Bounds.Top);
  Point point1 = new Point(imageList1.ImageSize.Width + 10, e.Bounds.Top + 5);
  Point point2 = new Point(imageList1.ImageSize.Width + 10, e.Bounds.Top + 25);
  Size size = new Size(listView1.ClientRectangle.Width, e.Bounds.Height);
  Rectangle R = new Rectangle(point0, size);
  Font F1 = new Font(listView1.Font.FontFamily, 11f, FontStyle.Bold);
  Font F2 = new Font(listView1.Font.FontFamily, 10f);

  if (e.Item.Focused) e.Graphics.FillRectangle(Brushes.LightBlue, R);
    else if (e.ItemIndex % 2 == 1) e.Graphics.FillRectangle(Brushes.GhostWhite, R);
  e.Graphics.DrawImage(imageList1.Images[e.Item.ImageIndex], point0 );
  e.Graphics.DrawString(e.Item.Text, F1, Brushes.Black, point1);
  e.Graphics.DrawString(e.Item.SubItems[1].Text, F2, Brushes.Black, point2);
  F1.Dispose(); F2.Dispose();
}

请注意,我有硬codeD几个颜色油漆每隔一行,也是重点项目。这些颜色真的应该使用相应的系统颜色。这些浮现在脑海中:

Note that I have hard-coded a few Colors to paint every other line and also the focused item. These colors really should use the respective System colors. These come to mind:

 SolidBrush brush0 = new SolidBrush(SystemColors.ControlLight);
 SolidBrush brush1 = new SolidBrush(SystemColors.Highlight);

我使用分配给了LV但具有中等大小的字体。显然或多或少的东西,尤其是各种偏移,可以配置自己的喜好。但是,使用的颜色来自于 System.Colors 收集留在你的用户的Windows主题保持好办法。

I am using the Font that is assigned to the LV but with moderate sizes. Obviously more or less anything, especially the various offsets, can be configured to your liking. But using colors from the System.Colors collection is good way to stay in keeping with your users' Windows themes.

这篇关于(ListView的?) - 控制就像在Windows资源管理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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