Sunday 15 July 2012

c# - "Custom Cursor cannot be converted to String" Exception is thrown while converting the cursor to string -


I'm trying to change the cursor control on certain conditions I have made your custom cursor and assign the cursor Have done Current property

When I check that the current control cursor and the new cursor are the same, then using the string method, changing the cursor is not based on their name, I get it:

There is no problem changing the default cursor of the system and it has increased only if the custom cursor is changed. Any one please please tell me why this exception was raised only on the custom cursor?

This is where I found the error ... ** If (m_cursorAction.ToString ()! = NewCursor.ToString ()) m_cursorAction = newCursor; **

Here is my cursor implementation code:

  Bitmap bitmap = new bitmap (140, 25); Graphics G = Graphics.from image (bitmap); (Font f = new font ("segoyi UI", 10)) g. Using dropsring ("node 30", f, system drawing brush, black, 0, 0); Cursor Current = microscope Buyer cursor (bitmap, 140, 25); ** If (m_cursorAction.ToString ()! = NewCursor.ToString ()) ** m_cursorAction = newCursor; Public Class Meeksar {#region class members are given the Private Static InterPTR PTR; Public structure IconInfo {public bool bikon; Public int xHotspot; Public Ent YHotspot; Public Input HBM Mask; Public Input HBM Callier; } #endregion #region Class Public Methods [System.Runtime.InteropServices.DllImport ( "user32.dll", charset = System.Runtime.InteropServices.CharSet.Auto)] public static exile bool DestroyIcon (IntPtr handle); [System.Runtime.InteropServices.DllImport ( "user32.dll", charset = System.Runtime.InteropServices.CharSet.Auto)] [return: System.Runtime.InteropServices.MarshalAs (System.Runtime.InteropServices.UnmanagedType.Bool)] Public static extern bool GetIconInfo (IntPtr hIcon, ref IconInfo pIconInfo); [System.Runtime.InteropServices.DllImport ( "user32.dll", charset = System.Runtime.InteropServices.CharSet.Auto)] public static exile IntPtr CreateIconIndirect ([System.Runtime.InteropServices.In] IconInfo icon referee); [System.Runtime.InteropServices.DllImport ("gdi32")] External internal fixed bool DeleteObject (IntPtr hObject); /// & lt; Summary & gt; /// Create a custom cursor with the given bitmap /// & lt; / Summary & gt; /// & lt; Param name = "bmp" & gt; Bitmap for cursor & Lt; / Param & gt; /// & lt; Param name = "xHotSpot" & gt; X hot spot for cursor & Lt; / Param & gt; /// & lt; Ultimate name = "yHotSpot" & gt; Hot place to the y-karta & Lt; / Param & gt; Public static System.Windows.Forms.Cursor CreateCursor (System.Drawing.Bitmap BMP, integer xHotSpot, integer yHotSpot) {IntPtr bmpPtr = bmp.GetHicon (); IconInfo Icon = New IconInfo (); GetIconInfo (bmpPtr, riff icon); Icon.xHotspot = xHotSpot; Icon.yHotspot = yHotSpot; Icon.bIcon = false; DestroyIcon (bmpPtr); DeleteObject (bmpPtr); Ptr = CreateIconIdirect (Riff Icon); System.Windows.Forms.Cursor cursor = new system.window.form. Cursor (ptr); // Delete GDI Objects and Icon Deleted Objects (icon.hbmColor); DeleteObject (icon.hbmMask); DestroyIcon (icon.hbmColor); DestroyIcon (icon.hbmMask); Return cursor; } /// & lt; Summary & gt; /// Delete custom cursor /// & lt; / Summary & gt; Public static zero destruction () {deleted icon (ptr); DeleteObject (PTR); } #endregion}  

Because it is representative to cursor cursor converter. , which is designed to throw only that exception to the custom cursor.

Do not just compare the test to use string comparison whether the cursor is the same or not. Instead, use the method designed to compare the cursor.

No comments:

Post a Comment