[DllImport("user32.dll")]
static extern IntPtr LoadCursorFromFile(string lpFileName);
[DllImport("user32.dll")]
static extern IntPtr SetCursor(IntPtr hCursor);
[DllImport("user32.dll")]
static extern bool SetSystemCursor(IntPtr hcur, uint id);
private const uint OCR_NORMAL = 32512;
static Cursor ColoredCursor;
<DllImport("user32.dll")> _
Public Shared Function SetCursor(ByVal hCursor As IntPtr) As IntPtr
End Function
None.
None.
Go Here For Even More!! Look at the second post.
http://social.msdn.microsoft.com/forums/en-US/winforms/thread/9ea0bf74-760f-4f40-b64c-0cf7b0a56939/
//==========C# Only
//========SET WINDOWS CURSOR========================================
IntPtr cursor = LoadCursorFromFile("example.cur");
bool ret_val = SetSystemCursor(cursor, OCR_NORMAL);
//========SET WINDOWS CURSOR========================================
//========SET FORM CURSOR========================================
IntPtr cursor = LoadCursorFromFile("example.cur");
ColoredCursor = new Cursor(cursor);
this.Cursor = ColoredCursor;
//========SET FORM CURSOR========================================
//========SET FORM CURSOR FROM IMAGE========================================
Bitmap hh = (Bitmap)System.Drawing.Bitmap.FromFile("example.png");
IntPtr ptr = hh.GetHicon();
Cursor c = new Cursor(ptr);
this.Cursor = c;
//========SET FORM CURSOR FROM IMAGE========================================
//========CONVERT System.Windows.Forms.Cursor TO System.Windows.Input.Cursor FOR WPF ========
using System.Drawing;
using Microsoft.Win32.SafeHandles;
public static Cursor CursorFromImage() // this returns a System.Windows.Input.Cursor
{
Bitmap image = (Bitmap)Bitmap.FromFile(@"c:\cursorImage.bmp");
IntPtr ptr = image.GetHicon();
System.Windows.Forms.Cursor c = new System.Windows.Forms.Cursor(ptr);
SafeFileHandle handle = new SafeFileHandle(c.Handle, false);
return yourCursor = System.Windows.Interop.CursorInteropHelper.Create(handle);
}
//===========================================================================================
//========USE AN IMAGE AS A RESOURCE IN WPF FROM AN "IMAGES" FOLDER (casts a PNG file to a Bitmap) =========================
using System.Drawing;
using Microsoft.Win32.SafeHandles;
using System.Windows.Resources;
public static Cursor CursorFromImage() // this returns a System.Windows.Input.Cursor
{
StreamResourceInfo sri = Application.GetResourceStream(new Uri("pack://application:,,,/Images/cursorImage.png"));
Bitmap image = (Bitmap)Bitmap.FromStream(sri.Stream);
IntPtr ptr = image.GetHicon();
System.Windows.Forms.Cursor c = new System.Windows.Forms.Cursor(ptr);
SafeFileHandle handle = new SafeFileHandle(c.Handle, false);
return yourCursor = System.Windows.Interop.CursorInteropHelper.Create(handle);
}
//=============================================================================================================================
Apply a custom cursor using the WPF examples like this:
this.Cursor = CursorFromImage(); // whole page
txtMyTextBox.Cursor = CursorFromImage(); // individual controls on mouse over
System.Windows.Forms.Cursor.Current