using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace MinimizeCapture
{
public partial class ListViewCostumControl : UserControl
{
public static ListViewControl lvnf;
public ListViewCostumControl()
{
InitializeComponent();
lvnf = new ListViewControl();
lvnf.Location = new Point(50, 50);
lvnf.Size = new Size(50, 50);
lvnf.View = View.SmallIcon;
lvnf.Dock = DockStyle.Fill;
lvnf.SuspendLayout();
lvnf.LabelEdit = true;
lvnf.Sorting = SortOrder.None;
this.Controls.Add(lvnf);
lvnf.ResumeLayout(false);
}
public class ListViewControl : System.Windows.Forms.ListView
{
public ListViewControl()
{
this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.EnableNotifyMessage, true);
}
protected override void OnNotifyMessage(System.Windows.Forms.Message m)
{
if (m.Msg != 0x14)
{
base.OnNotifyMessage(m);
}
}
}
public static class ListViewExtensions
{
public static ListViewItemCollection AddRange(this ListViewItemCollection source, WindowSnapCollection windows)
{
//Create a ListViewItem for each object and set the
//various properties appropriately
source.AddRange(from w in windows
select new ListViewItem(w.ToString())
{
Tag = w
});
return source;
}
public static WindowSnap GetWindowSnap(this ListViewItem source)
{
return source.Tag as WindowSnap;
}
public static WindowSnap GetSelectedWindowSnap(this ListView source)
{
return source.SelectedItem?.GetWindowSnap();
}
//Add more methods as needed
}
private void ListViewNFTest_Load(object sender, EventArgs e)
{
}
}
}
的错误是对线我试图做一个ListViewExtensions类,但得到了一些错误
public static ListViewItemCollection AddRange(this ListViewItemCollection source, WindowSnapCollection windows)
错误16类型或命名空间名称“ListViewItemCollection”找不到(是否缺少使用指令或程序集基准的?)
return source.SelectedItem?.GetWindowSnap();
错误18“System.Windows.Forms.ListView”不包含关于“的SelectedItem”和没有扩展方法“的SelectedItem”接受的第一定义类型“System.Windows.Forms.ListView”的说法可以找到(是否缺少using指令或程序集引用?)
错误19没有重载方法“GetWindowSnap”取0参数
签出文档 - [MSDN ListView.ListViewItemCollection](https://msdn.microsoft.com/en-us/library/system.windows.forms.listview.listviewitemcollection(v = vs.110).aspx) – MethodMan