[英]how to use custom cursor in vb.net
i have cursor.cur in my.resources.cursor我在 my.resources.cursor 中有 cursor.cur
but it doesn't work但它不起作用
then i tried icon it does work but when cursor is above buttons it needs to take alot above to click it然后我尝试了图标它确实有效但是当 cursor 在按钮上方时它需要在上面花费很多才能点击它
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim mycursor As Icon = My.Resources.normal ' normal is my curosor icon
Me.Cursor = New Cursor(mycursor.Handle)
End Sub
anybody can help me with working code i would also love if anybody can do this same by invoking win32任何人都可以帮助我编写工作代码,如果有人可以通过调用 win32 来做同样的事情,我也很乐意
Note you said that My.Resources.cursor
is the Class. 请注意,您说
My.Resources.cursor
是类。
Since it's a cursor file and not an icon file, try this: 由于它是游标文件而不是图标文件,请尝试以下操作:
Imports System
Private Sub Form1_Load(ByVal sender As Object, ByVal e as EventArgs) Handles MyBase.Load
Dim myCursor As New Cursor(New IO.MemoryStream(My.Resources.cursor.cursor)) 'Exception here indicates a 32bpp cursor.
End Sub
This, however, doesn't work with 32 bit-per-pixel cursors. 但是,这不适用于每像素32位的游标。 I recommend 24bpp.
我建议24bpp。
That also makes your cursor black and white. 这也会使您的光标变成黑色和白色。
Public Class ResxCursor
Private Declare Function LoadCursorFromFile Lib "user32" Alias "LoadCursorFromFileA" ( _
ByVal lpFileName As String) As IntPtr
Protected Shared ExtractDIR As String = IO.Path.GetFullPath(".")
Protected Shared _Cursor As Byte()
Public Shared Widening Operator CType(ByVal initialData As ResxCursour) As Cursor
Dim ExtractPath As String = ExtractDIR + _Cursor.GetHashCode.ToString
IO.File.WriteAllBytes(ExtractPath, _Cursor)
Dim CL As IntPtr = LoadCursorFromFile(ExtractPath)
Dim C As New Cursor(CL)
IO.File.Delete(ExtractPath)
Return C
End Operator
Sub New(Cursor As Byte())
_Cursor = Cursor
End Sub
End Class
Usage:用法:
Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Me.Button1.Cursor = New ResxCursor(My.Resources.MainFormResource.aero_pen)
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.