简体   繁体   English

我正在尝试制作ListViewExtensions类,但出现一些错误

[英]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.

相关问题 我正在尝试将Java脚本统一转换为csharp脚本,但出现一些错误? - I'm trying to convert java script in unity to csharp script but getting some errors? 我正在尝试使用SevenZipSharp压缩一些文件,但收到错误 - I'm trying to compress some files using SevenZipSharp but getting an error 我怎样才能使FOR向后循环? 遇到一些错误 - How can i make the FOR to loop backward ? Getting some errors 我正在尝试制作计算器,但我不断收到 CS0165,我不知道为什么 - I'm trying to make a calculator but I keep getting CS0165 and I'm confused as to why 我正在尝试重命名目录,但遇到两个错误,如何解决此错误? - I'm trying to rename directories but getting two errors, how to solve this errors? 我正在尝试获取过程信息并遇到两个错误,我该如何解决它们? - I'm trying to get process info and getting two errors how can i solve them? 我在将一个类引用到另一个类时遇到了一些问题,我得到的错误是我没有关于正式周界的论据 - I'm having some issues referencing a class to another class and the error I'm getting is I don't have an argument for a formal perimeter 我正在尝试读取进程的内存,但是由于某种原因,我没有获得正确的进程内存大小-怎么了? - I'm trying to read memory of a process but for some reason I'm not getting the right size of the process memory - what's wrong? 我正在尝试将一些文件从一个目录压缩到另一个目录,但我在其中一个目录上被拒绝访问? - I'm trying to compress some files from one directory to another but I'm getting access denied on one of the directories why? 我正在尝试从 sql 数据库登录,但不断收到此错误 - I´m trying to make a login from a sql database but keep getting this error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM