[英]I'm trying to make a ListViewExtensions class but getting some errors
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)
{
}
}
}
The errors are on the lines 错误在线
public static ListViewItemCollection AddRange(this ListViewItemCollection source, WindowSnapCollection windows)
Error 16 The type or namespace name 'ListViewItemCollection' could not be found (are you missing a using directive or an assembly reference?) 错误16找不到类型或名称空间名称'ListViewItemCollection'(您是否缺少using指令或程序集引用?)
return source.SelectedItem?.GetWindowSnap();
Error 18 'System.Windows.Forms.ListView' does not contain a definition for 'SelectedItem' and no extension method 'SelectedItem' accepting a first argument of type 'System.Windows.Forms.ListView' could be found (are you missing a using directive or an assembly reference?) 错误18'System.Windows.Forms.ListView'不包含'SelectedItem'的定义,并且找不到扩展方法'SelectedItem'接受类型为'System.Windows.Forms.ListView'的第一个参数(您是否缺少使用指令还是程序集引用?)
Error 19 No overload for method 'GetWindowSnap' takes 0 arguments 错误19方法'GetWindowSnap'没有重载接受0参数
It looks like you need to fully qualify some class names. 看来您需要完全限定某些类名。
The class ListViewItemCollection is defined in ListView. ListViewItemCollection类在ListView中定义。 So you need to fully qualify it with ListView.ListViewItemCollection. 因此,您需要使用ListView.ListViewItemCollection对其进行完全限定。
public static ListView.ListViewItemCollection AddRange(
this ListView.ListViewItemCollection source,
WindowSnapCollection windows)
WindowSnap and WindowSnap collection are not part of .NET, and you don't provide the definition so it's not clear how to use them. WindowSnap和WindowSnap集合不是.NET的一部分,您没有提供定义,因此不清楚如何使用它们。 Figure out where they are defined and use the full class name, including namespace. 找出它们的定义位置,并使用完整的类名,包括名称空间。 Replace all occurrences of WindowSnap with Namespace.WindowSnap
, and same goes for WindowSnapCollection. 用Namespace.WindowSnap
替换所有出现的WindowSnap,WindowSnapCollection也是如此。
See this MSDN article on fully qualified names for more info. 有关更多信息,请参见有关完全限定名称的MSDN文章 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.