setting a cursor hotspot (icon cursor)
I have a custom cursor that I have as a ico file as cur files are only mono coloured and 32x32.
The only problem in using a ico file is that I can't set where the hot spot is and at the moment it is set in the middle of the icon which is no help
I was looking on the msdn website and it said to set the hotspot like this
Code:
Dim instance As Cursor
Dim value As Point
value = instance.HotSpot
But I don't know how to set the point value to (0,54) which is where I want the hotspot to be located.
Re: setting a cursor hotspot (icon cursor)
heres an example:
vb Code:
#Region "CreateIconIndirect"
Private Structure IconInfo
Public fIcon As Boolean
Public xHotspot As Int32
Public yHotspot As Int32
Public hbmMask As IntPtr
Public hbmColor As IntPtr
End Structure
<DllImport("user32.dll", EntryPoint:="CreateIconIndirect")> _
Private Shared Function CreateIconIndirect(ByVal iconInfo As IntPtr) As IntPtr
End Function
<DllImport("user32.dll", CharSet:=CharSet.Auto)> _
Public Shared Function DestroyIcon(ByVal handle As IntPtr) As Boolean
End Function
<DllImport("gdi32.dll")> _
Public Shared Function DeleteObject(ByVal hObject As IntPtr) As Boolean
End Function
Public Function CreateCursor(ByVal bmp As Bitmap) As Cursor
'Setup the Cursors IconInfo
Dim tmp As New IconInfo
tmp.xHotspot = 0
tmp.yHotspot = 54
tmp.fIcon = False
tmp.hbmMask = bmp.GetHbitmap()
tmp.hbmColor = bmp.GetHbitmap()
'Create the Pointer for the Cursor Icon
Dim pnt As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(tmp))
Marshal.StructureToPtr(tmp, pnt, True)
Dim curPtr As IntPtr = CreateIconIndirect(pnt)
'Clean Up
DestroyIcon(pnt)
DeleteObject(tmp.hbmMask)
DeleteObject(tmp.hbmColor)
Return New Cursor(curPtr)
End Function
#End Region
Re: setting a cursor hotspot (icon cursor)
I did see that code before for making a bmp into a cursor
but where about's do I put the file location for the bmp if i made one of the ico file
also im getting a error at the > of each dll import
Re: setting a cursor hotspot (icon cursor)
the error - you need to import:
vb Code:
Imports System.Runtime.InteropServices
to create a cursor from an icon, add the code above to your form, then to call it:
vb Code:
me.cursor = CreateCursor(yourIcon.tobitmap)
Re: setting a cursor hotspot (icon cursor)
sorry do you mean like this
Code:
me.cursor = CreateCursor(F:\Cursors\curShark.ico.tobitmap)
Re: setting a cursor hotspot (icon cursor)
vb Code:
dim newIcon as new icon("F:\Cursors\curShark.ico")
me.cursor = CreateCursor(newIcon.tobitmap)
Re: setting a cursor hotspot (icon cursor)
thank you so much would have killed me to not be able to use this icon