自己加了一个光标文件在项目里
然后调用
Cursor = new Cursor(GetType(), "My.cur");
提示如下:
“未处理的“System.ArgumentNullException”类型的异常出现在 system.windows.forms.dll 中。
其他信息: 值不能为空。”
但是找了一个别人的程序
和我的没啥区别啊 人家的怎么就能用呢???
希望大家快快指点一下啊
拜托了
然后调用
Cursor = new Cursor(GetType(), "My.cur");
提示如下:
“未处理的“System.ArgumentNullException”类型的异常出现在 system.windows.forms.dll 中。
其他信息: 值不能为空。”
但是找了一个别人的程序
和我的没啥区别啊 人家的怎么就能用呢???
希望大家快快指点一下啊
拜托了
解决方案 »
- “茴”字的几种写法——C#中静态构造函数和静态变量文字执行顺序问题
- c# GDI+多个柱状和多条曲线缩放、切换 [源码1]
- 怎样将连接多个SQL语句自动变为一个字符串,省去人工用许多加号“+”和分号“"”连接各个SQL句子。见例子:
- Access怎么查询
- 用过CodeSmith 的朋友进来抢分了。
- WebServices中IDataParameter类型不能被序列化,还有其他方法吗
- 如何在listView的Items.subItem中显示图标??
- 条件解析
- 辞旧迎新,散掉所有分(208分,分两贴),但愿赶走今年的晦气,明年会更好!!!顺便问一下。。2
- 请问,在click函数中,怎样指导点的是左肩还是右键,点击位置
- 关于string的操作
- 怎样强制彻底结束一个应用程序?
在解决方案资源管理器里选中 My.cur 文件,按 F4 切换到“属性窗口”,
把生成操作改成“嵌入的资源”
{
Cursor a = new Cursor(GetType(), "My.cur");
this.Cursor = a;
}
但是如果一个命名空间是myspace.cursor.test
那么我在该命名空间下的类中写
Cursor a = new Cursor(GetType(), "My.cur");
就会出我在上面提出的那种错误
希望大家帮忙想想办法
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;
}
}可以使用呀。
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,真的不明白
希望高手解答一二
谢谢了
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;
}
}
}
this.Cursor = a;
{
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");
Cursor a=new Cursor(GetType(),"Finder.cur");
Cursor=a;
Finder.cur嵌入式资源
谢谢你的代码是可以用的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");
还是不好用
你的
Cursor a = new Cursor(t, "My.cur");
f.Cursor = a;
光标文件My.cur放在哪个目录下
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;
}
}
其实我最想要的是这种的
Cursor a = new Cursor(GetType(), "myspace.cursor.test.My.cur");
this.Cursor = a;
我就是搞不懂为什么我的代码不好用
xrye_ryan(叶祥润)能说得清楚点么?
Cursor = new Cursor(this.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),"文件夹名"+ "." + "文件名");
真的是不懂了
我也帮你试过了:
把光标文件放在项目目录下,在项目中添加mycur.cur
在mycur.cur上右击鼠标,属性,生成的操作选:嵌入的资源
就行了,怎么会不行呢?
Cursor a=new Cursor(GetType(),"mycur.cur");
Cursor=a;