Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8541891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:55:59+00:00 2026-06-11T11:55:59+00:00

I am trying to use custom images on Cursor and I did it with

  • 0

I am trying to use custom images on Cursor and I did it with these code.

public static class cursorHelper
{

    public static Cursor vertical = new Cursor(Application.GetResourceStream(getFromResource("PenCADwpf", "Images/cursors/Vertical.ico")).Stream);
    public static Cursor horizontal = new Cursor(Application.GetResourceStream(getFromResource("PenCADwpf", "Images/cursors/Horizontal.ico")).Stream);
    public static Uri getFromResource(string psAssemblyName, string psResourceName)
    {
        Uri oUri = new Uri("pack://application:,,,/" + psAssemblyName + ";component/" + psResourceName, UriKind.RelativeOrAbsolute);
        return oUri;
    }
    public static ImageSource getImageSourceFromResource(string psAssemblyName, string psResourceName)
    {
        Uri oUri = getFromResource(psAssemblyName, psResourceName);

        return BitmapFrame.Create(oUri);
    }

}

And using in code is

    private void btnVerticalMullion_Click(object sender, RoutedEventArgs e)
    {
        this.Cursor = cursorHelper.vertical;
    }

My problem is the hotspot of the Cursor is bottom-left point. I need to change it to 0,0 (top-left) point of the image. Can any body help me please?
Thanks in advance,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T11:56:00+00:00Added an answer on June 11, 2026 at 11:56 am

    It’s because you are using .ICO files instead of .CUR files as the data to the Cursor class.

    While the .ICO and .CUR file formats are similar, the .ICO format doesn’t contain the hotspot info.

    • http://en.wikipedia.org/wiki/ICO_(file_format)#cite_note-11

    You have 2 choices:

    • convert your .ICO files to .CUR files and embed those as resources instead

      Do that by using a conversion utility which you can find on the web,
      or
      create a new .CUR file in Visual Studio and then copy and paste the data from your .ICO files.

    • keep them as .ICO files but hack the data so it follows the CUR format when passed to the Cursor class.

    Here’s some example code to modify the ICO stream to turn it into the CUR format.

    In this example I tested it with an ICO file which contained a single 32X32X4bit BMP image, and I wanted the cursor to have a (15,15) hotspot.

    This code is just to get you started if you go down this route…it needs more code to handle errors, and the ability to deal with ICO files that contain multiple icon images (i.e. if multiple entries), etc.

    You could also use a BinaryWriter to more naturally handle the data e.g. for writing out hotspots coords that use 2 bytes (i.e. over 255) by using Write(UInt16).

    enter image description here

    enter image description here

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
    using System.IO;
    using System.Windows.Resources;
    
    namespace WpfApplication2
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
    
                Uri uri = new Uri("pack://application:,,,/test.ico");
    
                Stream iconstream = GetCURFromICO(uri, 15, 15 );
    
                Cursor cursor = new Cursor(iconstream);
    
                this.Cursor = cursor;
            }
    
            public static Stream GetCursorFromICO(Uri uri, byte hotspotx, byte hotspoty)
            {
                StreamResourceInfo sri = Application.GetResourceStream(uri);
    
                Stream s = sri.Stream;
    
                byte []buffer = new byte[s.Length];
    
                s.Read(buffer, 0, (int)s.Length);
    
                MemoryStream ms = new MemoryStream();
    
                buffer[2] = 2; // change to CUR file type
                buffer[10] = hotspotx;
                buffer[12] = hotspoty;
    
                ms.Write(buffer, 0, (int)s.Length);
    
                ms.Position = 0;
    
                return ms;
            }
    
            public static Stream GetCURFromICOAlternativeMethod(Uri uri, byte hotspotx, byte hotspoty)
            {
                StreamResourceInfo sri = Application.GetResourceStream(uri);
    
                Stream s = sri.Stream;
    
                byte []buffer = new byte[s.Length];
    
                MemoryStream ms = new MemoryStream();
    
                ms.WriteByte(0); // always 0
                ms.WriteByte(0);
                ms.WriteByte(2); // change file type to CUR
                ms.WriteByte(0);
                ms.WriteByte(1); // 1 icon in table
                ms.WriteByte(0);
    
                s.Position = 6; // skip over first 6 bytes in ICO as we just wrote
    
                s.Read(buffer, 0, 4);
                ms.Write(buffer, 0, 4);
    
                ms.WriteByte(hotspotx);
                ms.WriteByte(0);
    
                ms.WriteByte(hotspoty);
                ms.WriteByte(0);
    
                s.Position += 4; // skip 4 bytes as we just wrote our own
    
                int remaining = (int)s.Length - 14;
    
                s.Read(buffer, 0, remaining);
                ms.Write(buffer, 0, remaining);
    
                ms.Position = 0;
    
                return ms;
            }
        }
    }
    

    <Window x:Class="WpfApplication2.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="350" Width="525">
        <Grid>
    
        </Grid>
    </Window>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a custom cursor using the following image: http://anuary.com/dev/hp/pad3/public/images/hand-cursor.png The
I am trying to use custom images for checkboxes and radio buttons. So far
I am trying to use custom cursor in my game using nscursor. I use
I'm trying to use custom meta boxes in wordpress. My goal at the moment
I'm trying to use custom check boxes within Fancybox. They are showing up but
I am trying to use a custom segue to perform a kind of zoom
I'm trying to use a custom validator with jQuery Validation plugin. However, I'm unsure
I'm trying to use a custom UITableViewCell, and I've placed it in the same
I'm trying to use a custom font with the text in my Widget. Since
I'm trying to use phantom.js custom buildpack on Heroku ( https://github.com/stomita/heroku-buildpack-phantomjs ) I followed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.