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.
Code:
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.
Code:
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
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());
}
}
}