Torna al Thread

Imports System.Runtime.InteropServices Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim bitmap As Bitmap = Image.FromFile("C:\mano.png") Me.Cursor = CreaCursore(bitmap, 3, 3) bitmap.Dispose() End Sub Public Structure IconInfo Public fIcon As Boolean Public xHotspot As Integer Public yHotspot As Integer Public hbmMask As IntPtr Public hbmColor As IntPtr End Structure 'Crea un cursore valido a partire da una struttura IconInfo e restituisce 'un puntatore al cursore <DllImport("user32.dll", EntryPoint:="CreateIconIndirect")> Public Shared Function Icona(ByRef icon As IconInfo) As IntPtr End Function 'Ottiene delle informazioni sull'icona hIcon specificata come puntatore (o come valore 'notevole se identifica un cursore predefinito) e le pone In pIconInfo. <DllImport("user32.dll", EntryPoint:="GetIconInfo")> Public Shared Function InfoIcona(ByVal hIcon As IntPtr, ByRef pIconInfo As IconInfo) As Boolean End Function Public Function CreaCursore(ByVal bmp As Bitmap, ByVal xHotSpot As Integer, ByVal yHotSpot As Integer) As Cursor Dim tmp As New IconInfo() 'Crea una nuova struttura IconInfo riguardando l'icona ottenuta dalla funzione bmp.GetHicon() e la mette In tmp InfoIcona(bmp.GetHicon(), tmp) 'Coordinate del'"hot spot" del cursore. Presumo che sia il punto che "fa click" tmp.xHotspot = xHotSpot tmp.yHotspot = yHotSpot 'False indica che si tratta di un cursore e non una semplice icona tmp.fIcon = False Return New Cursor(Icona(tmp)) End Function
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5