6月 13

マウスカーソルの形状を変更する(ユーザー定義)

マウスカーソル形状を
ユーザー定義のマウスカーソルファイル(.cur)
に変更する場合の例です。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            // デフォルトのカーソルに戻す
            this.Cursor = Cursors.Default;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // ユーザー定義のカーソルに変更
            this.Cursor = @"c:\temp\custom.cur";
        }
    }
}
6月 13

マウスカーソルの形状を変更する

Cursorプロパティーの値を変更します。
Form上でカーソルを変更したい場合は
FormのCursorプロパティーの値を変更します。

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.AppStarting;  // 矢印+砂時計

            // ここで何か重い処理など

            this.Cursor = Cursors.Arrow;        // 通常の矢印に戻す
        }
    }