Changing the cursor

D

Dom

I need to change the cursor when the mouse is hovering over certain
cells in a DataViewGrid, as a visual aid for the user. But the cursor
is not something found in the Cursors Class. I have a .ICO file.

What is the most efficient way of doing this? Is a way to build the
cursor resource right into the executable, so that it travels with
the EXE? That seems to be the way other programs do it. For example,
I have a resource viewer that lets me see all the resources in Excel,
and I can find Icons, Cursors, etc.

Right now, what I do is this. In the load event of the main window, I
do m_AlternateCursor = new Cursor (<AppStartupPath>\filename), and I
plan to include the ICO file in the executable folder.
 
N

Nicholas Paldino [.NET/C# MVP]

Dom,

That's what I would do. You wouldn't have to worry about the file being
changed or deleted (of course, it means you have to recompile if the cursor
changes).

You can just add the file to your project and set the compile action to
"embedded resource" and then you would call the GetManifestResourceStream
method on the Assembly class (the instance would represent the assembly you
are getting the embedded resource from). You could then pass that Stream to
the Cursor class, and use it appropriately.
 
P

Peter Duniho

I need to change the cursor when the mouse is hovering over certain
cells in a DataViewGrid, as a visual aid for the user. But the cursor
is not something found in the Cursors Class. I have a .ICO file.

What is the most efficient way of doing this? Is a way to build the
cursor resource right into the executable, so that it travels with
the EXE?

Yes, just add a new Icon resource to the Resources of your project, using
the .ico file you have as the input.

You can then reference the icon from the Properties.Resources class of
your project.

I do agree that this is better than trying to include a separate file in
the same directory with your .exe, though assuming you're using a normal
Setup program to install the program, it shouldn't matter much which way
you do it since the user should never have to care about copying the files
manually.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top