Ejemplo n.º 1
0
        public static Cursor InternalCreateCursor(System.Drawing.Bitmap bmp,
            int xHotSpot, int yHotSpot)
        {
          //IconInfo tmp = new IconInfo();
          //GetIconInfo(bmp.GetHicon(), ref tmp);
          //tmp.xHotspot = xHotSpot;
          //tmp.yHotspot = yHotSpot;
          //tmp.fIcon = false;

          //IntPtr ptr = CreateIconIndirect(ref tmp);
          //SafeFileHandle handle = new SafeFileHandle(ptr, true);
          //return CursorInteropHelper.Create(handle);



          var iconInfo = new IconInfo();
          GetIconInfo(bmp.GetHicon(), ref iconInfo);
          iconInfo.xHotspot = xHotSpot;
          iconInfo.yHotspot = yHotSpot;
          iconInfo.fIcon = false;

          SafeIconHandle cursorHandle = CreateIconIndirect(ref iconInfo);
          return CursorInteropHelper.Create(cursorHandle);

        }
Ejemplo n.º 2
0
		public static System.Windows.Forms.Cursor CreateCursor( System.Drawing.Bitmap bmp, int xHotSpot, int yHotSpot ) {
			IconInfo tmp = new IconInfo();
			GetIconInfo( bmp.GetHicon(), ref tmp );
			tmp.xHotspot = xHotSpot;
			tmp.yHotspot = yHotSpot;
			tmp.fIcon = false;
			return new System.Windows.Forms.Cursor( CreateIconIndirect( ref tmp ) );
		}
Ejemplo n.º 3
0
    private static Cursor InternalCreateCursor(System.Drawing.Bitmap bmp, int xHotSpot, int yHotSpot)
    {
      var iconInfo = new NativeMethods.IconInfo();
      NativeMethods.GetIconInfo(bmp.GetHicon(), ref iconInfo);

      iconInfo.xHotspot = xHotSpot;
      iconInfo.yHotspot = yHotSpot;
      iconInfo.fIcon = false;

      SafeIconHandle cursorHandle = NativeMethods.CreateIconIndirect(ref iconInfo);
      return CursorInteropHelper.Create(cursorHandle);
    }
Ejemplo n.º 4
0
    private static Cursor InternalCreateCursor(System.Drawing.Bitmap bmp,
        int xHotSpot, int yHotSpot)
    {
      IconInfo tmp = new IconInfo();
      GetIconInfo(bmp.GetHicon(), ref tmp);
      tmp.xHotspot = xHotSpot;
      tmp.yHotspot = yHotSpot;
      tmp.fIcon = false;

      IntPtr ptr = CreateIconIndirect(ref tmp);
      SafeFileHandle handle = new SafeFileHandle(ptr, true);
      return CursorInteropHelper.Create(handle);
    }
Ejemplo n.º 5
0
        /// <summary>
        /// Create an icon from a bitmap.
        /// </summary>
        /// <param name="resourceBitmap">Bitmap to be transformed.</param>
        /// <returns>An Icon.</returns>
        public static System.Drawing.Icon BitmapToIcon(System.Drawing.Bitmap resourceBitmap)
        {
            IntPtr Hicon = resourceBitmap.GetHicon();

            return System.Drawing.Icon.FromHandle(Hicon);
        }
Ejemplo n.º 6
0
 internal void SetIcon(System.Drawing.Bitmap bitmap)
 {
     if (bitmap != null)
     {
         IntPtr Hicon = bitmap.GetHicon();
         this.Icon = System.Drawing.Icon.FromHandle(Hicon);
     }
 }
Ejemplo n.º 7
0
        public static void SetHWCursorBitmap(System.Drawing.Bitmap b)
        {

            System.Windows.Forms.Form f = System.Windows.Forms.Control.FromHandle(MyInput.Static.WindowHandle) as System.Windows.Forms.Form;
            if (f != null)
            {
                // TODO: OP! Make this in thread safe way and optimized
                f.Invoke(new Action(() => f.Cursor = new System.Windows.Forms.Cursor(b.GetHicon())));
            }
        }
Ejemplo n.º 8
0
 public static void SetHWCursorBitmap(System.Drawing.Bitmap b)
 {
     System.Windows.Forms.Form f = System.Windows.Forms.Control.FromHandle(MyInput.Static.WindowHandle) as System.Windows.Forms.Form;
     if (f != null)
     {
         // TODO: OP! Make this in thread safe way and optimized
         f.BeginInvoke((MethodInvoker)(() => f.Cursor = new System.Windows.Forms.Cursor(b.GetHicon()))); //FIX 2, this does not lock thread .
     }
 }
Ejemplo n.º 9
0
 public static void SetHWCursorBitmap(System.Drawing.Bitmap b)
 {
     System.Windows.Forms.Form f = (System.Windows.Forms.Form)System.Windows.Forms.Form.FromHandle(MyMinerGame.Static.Window.NativeWindow.Handle);
     f.Cursor = new System.Windows.Forms.Cursor(b.GetHicon());
 }