How to import a cursor. cur in C#

Asked

Viewed 141 times

1

I have a problem loading a cursor file in Windows Forms.

Type I put the files in the folder but the program notes that the course file is not valid or is corrupted. But I really need these cursors to develop an applicator.

I tried using this code to solve my problem:


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

but the above mentioned code did not work.

I tried this one too but it didn’t work either:


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

The VS2010 says the following message:

Invalid image format. Maybe the image file is corrupted.
Name of the parameter: stream

  • Just citing what is being argued is Exception: Argumentexception

  • 1

    But do you have any questions? The error message is very clear what your problem is. The problem is not in the code. Either of the two ways may be correct or wrong, just with this snippet you can’t know which one is right but it doesn’t matter because the error occurs before assigning to any member.

1 answer

1

Add the . cur in your application’s Resources... there it will be next to your project and it 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 so:

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

For this last case... Voce can get the correct name using the following command(pull all resourcesname from the Resources folder):

String[] resourceNames = Assembly.GetExecutingAssembly().GetManifestResourceNames();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.