12

WinFormsでカスタムカーソルを使用する方法はありますか?

選択肢がないようです。しかし、手動でカーソルをリソースとして追加し、それをコードから呼び出そうとすると、byte[]タイプからCursorに変換できないと表示されます。

4

5 に答える 5

12

C# でカーソルにカスタム アイコンを追加する:

プロジェクト リソースにアイコン ファイルを追加します (例: Processing.ico)。

そして、画像のプロパティウィンドウで「ビルドアクション」を「埋め込み」に切り替えます

Cursor cur = new Cursor(Properties.Resources.**Imagename**.Handle);
this.Cursor = cur;

Ex:

Cursor cur = new Cursor(Properties.Resources.Processing.Handle);
this.Cursor = cur;
于 2011-09-21T09:25:28.873 に答える
4

クラスに関する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");
于 2010-05-09T08:48:54.633 に答える
1

LoadCursorFromFile()User32.dllのメソッドを使用しました。これについては、ウェブ上にたくさんのサンプルがあります。

また

型の ctor にCursorIO.Streamオーバーロードがあります。を にロードbyte[]し、MemoryStreamそれを新しい にフィードしますCursor

于 2010-05-09T08:44:01.723 に答える
0

ファイルをリソースに追加した後、画像のプロパティウィンドウで、次のように切り替えBuild ActionEmbedded Resourceコードを記述します。

"name of control".Cursor = new System.Windows.Forms.Cursor(Properties.Resources."name of image".Handle);
于 2012-05-22T12:05:23.043 に答える