指定したリソースの種類を使用して、指定したリソースで Cursor クラスの新しいインスタンスを初期化します。
Public Sub New( _
ByVal type As Type, _ ByVal resource As String _)
[C#]
public Cursor(
Typetype,stringresource);
[C++]
public: Cursor(
Type* type,String* resource);
[JScript]
public function Cursor(
type : Type,resource : String);
パラメータ
- type
リソース Type 。 - resource
リソースの名前。
解説
アプリケーション内にリソースとしてカーソルを埋め込む方法を次の例に示します。リソースを埋め込むには、リソース名とアセンブリの完全パスをコンマで区切って参照を指定します。埋め込まれたリソースからカーソルを読み込む方法については、例のセクションを参照してください。
Using the C# compiler:
csc /resource:"MyWaitCursor.cur","MyCursors.MyWaitCursor.cur" MyCursor.cs
Using the Visual Basic compiler:
vbc /resource:"MyWaitCursor.cur","MyCursors.MyWaitCursor.cur" MyCursor.vb
メモ リソースを参照するとき (コンパイル時およびコード内での参照時) は、C# コンパイラおよび Visual Basic コンパイラの両方で大文字と小文字が区別されます。
使用例
[Visual Basic, C#, C++] System.Windows.Forms.Cursor.#ctor コンストラクタを使用して、カスタム カーソルの使用方法を示すフォームを表示する例を次に示します。カスタム Cursor は、アプリケーションのリソース ファイルに組み込まれています。この例では、 MyCursor.cur
という名前のカーソル ファイルにカーソルが格納されていることを前提にしています。コマンド ラインでこの例をコンパイルするには、フラグ /res:MyCursor.Cur, CustomCursor.MyCursor.Cur を格納します。
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Namespace CustomCursor
Public Class Form1
Inherits System.Windows.Forms.Form
<System.STAThread()> _
Public Shared Sub Main()
System.Windows.Forms.Application.Run(New Form1())
End Sub 'Main
Public Sub New()
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Text = "Cursor Example"
' Looks namespace.MyCursor.cur in the assemblies manifest.
' 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
'
' 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 acase sensitive.
Me.Cursor = New Cursor(Me.GetType(), "MyCursor.Cur")
End Sub 'New
End Class 'Form1
End Namespace 'CustomCursor
[C#]
using System;
using System.Drawing;
using System.Windows.Forms;
namespace CustomCursor
{
public class Form1 : System.Windows.Forms.Form
{
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
public Form1()
{
this.ClientSize = new System.Drawing.Size(292, 266);
this.Text = "Cursor Example";
// 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 acase sensitive.
this.Cursor = new Cursor(GetType(), "MyCursor.Cur");
}
}
}
[C++]
using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;
namespace CustomCursor {
public __gc class Form1 : public System::Windows::Forms::Form {
public:
Form1() {
this->ClientSize = System::Drawing::Size(292, 266);
this->Text = S"Cursor Example";
// 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 System::Windows::Forms::Cursor(GetType(), S"MyCursor.Cur");
}
};
}
[STAThread]
int main() {
Application::Run(new CustomCursor::Form1());
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
参照
Cursor クラス | Cursor メンバ | System.Windows.Forms 名前空間 | Cursor コンストラクタのオーバーロードの一覧 | コマンド ラインからのビルド (C#) | コマンド ラインからのビルド (VB)