tags:

views:

31

answers:

3

Hi, I am creating a Control Library project. I have some Cursor files which i want to add on resources.

Because on Resources.resx--->Add resources is only for String, Icon (.ico), Text file(.txt), Image (Png,bmp,jpeg,gif, tiff) files.

So where i can add *.cur files. How can i do it?

thanks

A: 

If you click "Add Resources..." There is an option for "Add Existing File..." Choose it and select your file.

David Morton
i tried this earlier but i have problem with the code generated by Resource file.See the code when you add any image file.(Bmp, Png, ico,Gif,Tiff)Resource file generate following code internal static System.Drawing.Bitmap QuestionIcon { get { object obj = ResourceManager.GetObject("YourIconName", resourceCulture); return ((System.Drawing.Bitmap)(obj)); } }It return Bitmap which you can easily use in your project like.public Bitmap questImage = Test.Properties.Resources.QuestionIcon ;
prashant
But When you add cur file it return a byte [] like below. internal static byte[] mdColor { get { object obj = ResourceManager.GetObject("mdColor", resourceCulture); return ((byte[])(obj)); } }I tried to convert it into Cursor but not successful.See my codepublic byte[] magImage = CursorTest.Resource1.mdRectMag;unsafe { fixed (byte* ptr = magImage){ IntPtr myPtr = new IntPtr((void*)ptr);Cursor myCur = new Cursor(myPtr); return myCur;}return null;}
prashant
+1  A: 

There is also a category Other. There you can add anything you like.

Also you can click on the little down arrow next to Add Resource and click on Add Existing File .... It will put it automatically in the correct category.

Update

Ok. So the problem is not adding the file to the resources. Instead loading it from there makes the problem, cause the Cursor class only supports a Stream, but not a byte[].

In that case you should put it into a MemoryStream and give this to the Cursor constructor.

Cursor myCursor;
using (var memoryStream = new MemoryStream(Properties.Resources.MyCursorFile))
{
    myCursor = new Cursor(memoryStream);
}
Oliver
see my comment given to David Morton.I have problem with converting byte [] of cursor (generated by resouces file) into Cursor object.Thanks
prashant
A: 

thanks Friends

I have done it.
I used following code for conversion:

Cursor My = new Cursor(new System.IO.MemoryStream(CursorTest.Resource1.MyCurFile));
prashant
Oh, seems that you already found the solution by yourself, but you should put the MemoryStream into a using statement like in my example or call `myMemoryStream.Close()`.
Oliver