2016-05-03 73 views
0
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参数

+1

签出文档 - [MSDN ListView.ListViewItemCollection](https://msdn.microsoft.com/en-us/library/system.windows.forms.listview.listviewitemcollection(v = vs.110).aspx) – MethodMan

回答

0

它看起来就像你需要完全限定一些类名一样。

类ListViewItemCollection在ListView中定义。所以你需要用ListView.ListViewItemCollection完全限定它。

public static ListView.ListViewItemCollection AddRange(
    this ListView.ListViewItemCollection source, 
    WindowSnapCollection windows) 

WindowSnap和WindowSnap集合不是.NET的一部分,并且您不提供定义,因此不清楚如何使用它们。找出它们的定义位置并使用完整的类名称,包括名称空间。将所有出现的WindowSnap替换为Namespace.WindowSnap,对于WindowSnapCollection也是如此。请参阅this MSDN article以获取更多信息。

+0

你的权利是WindowSnapCollection.cs代码http://pastebin.com/ZGydKNWi,这是WindowSnap.cs代码http://pastebin.com/8nCDhT9U –

+0

确定它与代码的其余部分位于相同的命名空间中。它在同一个项目中吗?当然,编译器已经问过你了,但是:“找不到类型或名称空间名称'WindowSnap'(**你是否缺少使用指令或程序集引用?**)” – djv

+0

你在pastebin中的两个代码文件必须要么与问题代码位于同一个项目中,要么位于不同项目中,则必须使用上述代码从项目中添加对该项目的引用,或者将它们移动到同一个项目中。 – djv

相关问题