Использование пользовательского курсора WinForms

Существует ли способ использовать пользовательский курсор в winforms?

Кажется, нет никакой опции. Но когда я пытаюсь вручную добавить курсор как ресурс, затем назовите его из кода, он говорит, что он не может преобразовать из байта типа [] к Курсору.

9
задан 9 May 2010 в 08:39
поделиться

2 ответа

Из документации MSDN по классу Cursor (с небольшими исправлениями):

// The following generates a cursor from an embedded resource.
// To add a custom cursor, create or use an existing 16x16 bitmap
//        1. Add a new cursor file to your project: 
//                File->Add New Item->Local Project Items->Cursor File
//        2. Select 16x16 image type:
//                Image->Current Icon Image Types->16x16
// --- To make the custom cursor an embedded resource  ---
// In Visual Studio:
//        1. Select the cursor file in the Solution Explorer
//        2. Choose View->Properties.
//        3. In the properties window switch "Build Action" to "Embedded"
// On the command line:
//        Add the following flag:
//            /res:CursorFileName.Cur,Namespace.CursorFileName.Cur
//        
//        Where "Namespace" is the namespace in which you want to use
//        the cursor and   "CursorFileName.Cur" is the cursor filename.
// The following line uses the namespace from the passed-in type
// and looks for CustomCursor.MyCursor.Cur in the assemblies manifest.
// NOTE: The cursor name is case sensitive.

this.Cursor = new Cursor(GetType(), "MyCursor.Cur");
4
ответ дан 4 December 2019 в 13:00
поделиться

Я использовал LoadCursorFromFile() метод из User32.dll. В Интернете есть много примеров для этого.

ИЛИ

В ctor для типа Cursor также есть перегрузка IO.Stream. Загрузите byte[] в MemoryStream и передайте его новому Cursor.

1
ответ дан 4 December 2019 в 13:00
поделиться
Другие вопросы по тегам:

Похожие вопросы: