Results 1 to 2 of 2

Thread: Using PNG image as cursor in WPF

  1. #1

    Thread Starter
    Addicted Member Kram Kramer's Avatar
    Join Date
    Dec 2016

    Using PNG image as cursor in WPF

    1- Create a Winform / vb.net project.

    2- Put a png file on your desktop and name it as myimage.png

    3- The following code changes the cursor.

    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
            'Fisrt convert your image to bmp format
            Dim myImage As Image = Image.FromFile("C:\Users\Yourname\Desktop\myimage.png")
            Using myMemoryStream As New IO.MemoryStream()
                myImage.Save(myMemoryStream, Imaging.ImageFormat.Bmp)
            End Using
            Dim myPictureBox As New PictureBox
            myPictureBox.Image = myImage
            Me.Cursor = New Cursor(DirectCast(myPictureBox.Image, Bitmap).GetHicon())
        End Sub
    End Class
    My question is here:

    I want the same action in WPF.

    So do you know WPF version of the above code?

    This is C# version of the above code.

    namespace WindowsFormsApplication1
    public partial class Form1 : Form
        public Form1()
            Image myImage = Image.FromFile("C:\\Users\\Yourname\\Desktop\\myimage.png");
            using (System.IO.MemoryStream myMemoryStream = new System.IO.MemoryStream())
                myImage.Save(myMemoryStream, System.Drawing.Imaging.ImageFormat.Bmp);
            PictureBox myPictureBox = new PictureBox();
            myPictureBox.Image = myImage;
            this.Cursor = new Cursor(((Bitmap)myPictureBox.Image).GetHicon());
    Last edited by Kram Kramer; May 18th, 2020 at 08:34 PM.

  2. #2
    Junior Member
    Join Date
    Jan 2020

    Re: Using PNG image as cursor in WPF

    Hii Kram,

    I got some sites to create cursor using png image.

    Please check the below links...

    I hope it will help you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts


Click Here to Expand Forum to Full Width