自己加了一个光标文件在项目里
然后调用
Cursor = new Cursor(GetType(), "My.cur");
提示如下:
“未处理的“System.ArgumentNullException”类型的异常出现在 system.windows.forms.dll 中。
其他信息: 值不能为空。”
但是找了一个别人的程序
和我的没啥区别啊 人家的怎么就能用呢???
希望大家快快指点一下啊
拜托了

解决方案 »

  1.   


    在解决方案资源管理器里选中 My.cur 文件,按 F4 切换到“属性窗口”,
    把生成操作改成“嵌入的资源”
      

  2.   

    private void Form3_Load(object sender, System.EventArgs e)
    {
    Cursor a = new Cursor(GetType(), "My.cur");
    this.Cursor = a;
    }
      

  3.   

    当位于一个扁平的一层的命名空间时是可以的
    但是如果一个命名空间是myspace.cursor.test
    那么我在该命名空间下的类中写
    Cursor a = new Cursor(GetType(), "My.cur");
    就会出我在上面提出的那种错误
    希望大家帮忙想想办法
      

  4.   

    ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/cpref/html/frlrfsystemwindowsformscursorclassctortopic4.htm
      

  5.   

    不明白你的意思,你贴一下你的代码?你的意思是在一个单独的类里设置你的 Cursor ?
    private void Form3_Load(object sender, System.EventArgs e)
    {
    test t = new test(this);
    }class test
    {
    public test(Form f)
    {
    Cursor a = new Cursor(GetType(), "My.cur");
    f.Cursor = a;
    }
    }可以使用呀。
      

  6.   

    to hdt(近来工作忙,每天只能接分半个小时)
          xrascal(横刀夺爱) 
    ————这个帮助我看了好多次了
    给你们看看我的代码
    using System;
    using System.Windows.Forms;
    using System.Drawing;namespace DrawFree
    {
    /// <summary>
    /// Rectangle tool
    /// </summary>
    public class ToolRectangle : ToolObject
    { public ToolRectangle()
    {
    //new Cursor( typeof(Cursor), GetType().Namespace + ".cursorname.cur");
                Cursor = new Cursor(GetType(), "Rectangle.cur");
    //Cursor = new Cursor(GetType(), "Cursor1.cur");

    //Cursor = new Cursor(GetType(), "cn.net.plt.oilport.draw.drawobject.Rectangle.cur");
    }
    ————注意 这里的namespace是DrawFree,如果改成了King.DrawFree就完全不行了
    不信的话把你们的代码的namespace改一下,看看运行之后怎么个效果
    呵呵
    我在做一个画图程序 参考的是http://www.codeproject.com/csharp/DrawTools.asp
    他参考的是DrawCLI 在msdn帮助里面就能找到 不过是C++的
    大家一起学习学习吧
    还有就是我不知道他为什么要把代码分为DrawXXX和ToolXXX,真的不明白
    希望高手解答一二
    谢谢了
      

  7.   

    Form6.cs***********************************************************
    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;namespace WindowsApplication15
    {
    public class Form6 : System.Windows.Forms.Form
    {
    private System.ComponentModel.Container components = null; public Form6()
    {
    InitializeComponent();
    } protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if(components != null)
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } private void InitializeComponent()
    {
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(292, 273);
    this.Name = "Form6";
    this.Text = "Form6";
    this.Load += new System.EventHandler(this.Form6_Load); } private void Form6_Load(object sender, System.EventArgs e)
    {
    King.DrawFree.ToolRectangle toolRectangle = new King.DrawFree.ToolRectangle(typeof(Form6),this);

    }
    }
    }
    ************************************************************
    ToolRectangle.cs
    ************************************************************using System;
    using System.Windows.Forms;namespace King.DrawFree
    {
    public class ToolRectangle
    {
    public ToolRectangle(Type t, Form f)
    {
    Cursor a = new Cursor(t, "My.cur");
    f.Cursor = a;
    }
    }
    }
      

  8.   

    Cursor a = new Cursor(GetType(), "myspace.cursor.test.My.cur");
    this.Cursor = a;
      

  9.   

    看楼上codeproject那个,好用的,我以前也用这个
      

  10.   

    资源文件的全路径名应该是namespace + "." + 文件夹名 + ... + "." + 直属文件夹名 + "." + 资源名。并且资源必须是内嵌的,即embedded.
      

  11.   

    public static Cursor LoadCursor(string resourceName)
    {
    try
    {
    using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
    {
    return new Cursor(stream);
    }
    }
    catch(Exception ex)
    {
    Debug.WriteLine(ex);
    }
    return null;
    }
    }
    你只要在程序中加入
    Cursor a=LoadCursor("mycursor.cur");
      

  12.   

    不过你自己那个也就能用了啊:
    Cursor a=new Cursor(GetType(),"Finder.cur");
    Cursor=a;
    Finder.cur嵌入式资源
      

  13.   

    to lovevsnet(编程一把手)
    谢谢你的代码是可以用的to xrye_ryan(叶祥润) 
    你说的:资源文件的全路径名应该是namespace + "." + 文件夹名 + ... + "." + 直属文件夹名 + "." + 资源名。
    其中namespace是 Cursor a=new Cursor(GetType(),"Finder.cur");所在文件的namespace么?
    怎么有两个文件夹名呢?
    我在自己的工程下面建立了一个test文件夹,然后在主窗体里面写
    this.Cursor = new Cursor(GetType(),"King.net.cn.LoadCursor.test.Cursor1.cur");
    还是不好用
      

  14.   

    to xrascal(横刀夺爱) (
    你的 
    Cursor a = new Cursor(t, "My.cur");
    f.Cursor = a;
    光标文件My.cur放在哪个目录下
      

  15.   

    //设置动态光标
    public class BDCursor
    {
    [DllImport("USER32.Dll")]
    private static extern IntPtr LoadCursorFromFile( string IpFileName ); [DllImport("USER32.Dll")]
    private static extern IntPtr SetCursor( IntPtr hCursor ); [DllImport("USER32.Dll")]
    private static extern uint DestoryCursor( IntPtr hCursor ); public static Cursor GetBDCursor( String fileName, IntPtr cursorPtr )
    {
    Cursor resultCursor = new Cursor( cursorPtr );
    IntPtr customCursor = LoadCursorFromFile( fileName );
    resultCursor.GetType().InvokeMember("handle",BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.Instance|BindingFlags.SetField,null,resultCursor,new object[]{ customCursor });
    return resultCursor;
    }
    }
      

  16.   

    谢谢zhgroup() 老兄了
    其实我最想要的是这种的 
    Cursor a = new Cursor(GetType(), "myspace.cursor.test.My.cur");
    this.Cursor = a;
    我就是搞不懂为什么我的代码不好用
     xrye_ryan(叶祥润)能说得清楚点么?
      

  17.   

    给个正确答案吧
    Cursor = new Cursor(this.GetType(),"文件夹名"+ "." + "文件名");
      

  18.   

    GetType()其实就是指定命名空间的地方.
    比如默认命名空间为 mynamespace
    嵌入的资源 my.cur
    类 class1.cs 命名空间为 mynamespace
    类 class2.cs 命名空间为 mynamespace.test在类 class1 中可以直接使用
    Cursor = new Cursor(this.GetType(),"文件夹名"+ "." + "文件名");在类 class2 中则要这样使用
    Cursor = new Cursor((new Class1()).GetType(),"文件夹名"+ "." + "文件名"); 或
    Cursor = new Cursor(typeof(Class1),"文件夹名"+ "." + "文件名"); 
      

  19.   

    文件夹名?是在项目文件夹下的还是在相对于bin目录的一个相对路径名???
    真的是不懂了
      

  20.   

    项目文件夹下的,不是相对与bin
      

  21.   

    楼主,我必须要告诉你的是,你自己的代码可用的
    我也帮你试过了:
    把光标文件放在项目目录下,在项目中添加mycur.cur
    在mycur.cur上右击鼠标,属性,生成的操作选:嵌入的资源
    就行了,怎么会不行呢?
    Cursor a=new Cursor(GetType(),"mycur.cur");
    Cursor=a;