How to import a .cur cursor into C #

1

I'm having a problem loading a cursor file into Windows Forms.

I type the files in the folder but the program notices that the course file is not valid or is corrupted. But I really need these cursors for developing an application.

I tried to use this code to solve my problem:


void FormLoaded(object sender, EventArgs e){
    this.Cursor = new Cursor("app\point.cur");
}

but the code quoted above did not work.

I tried this too but it did not work either:


void FormLoaded(object sender, EventArgs e){
    Cursor.Current = new Cursor("app\point.cur");
}

VS2010 says the following message:

Invalid image format. The image file may be corrupted. Parameter name: stream

    
asked by anonymous 27.09.2014 / 04:15

1 answer

1

Add the .cur in the resources of your application ... then it will be next to your project and will not be an external file to your project.

So much so:

this.Cursor = new Cursor(new System.IO.MemoryStream(Properties.Resources.point));

How much:

this.Cursor = new Cursor(Assembly.GetExecutingAssembly().GetManifestResourceStream("NomeAplicacao.point.cur"));

For this latter case ... you can get the correct name using the following command (pulls all resourcesname from the resources folder):

String[] resourceNames = Assembly.GetExecutingAssembly().GetManifestResourceNames();
    
29.09.2014 / 06:17