Cursor Swap : Cursors « GUI Windows Forms « C# / CSharp Tutorial

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / C Sharp
C# / C Sharp by API
C# / CSharp Open Source
C# / CSharp Tutorial » GUI Windows Forms » Cursors 
23.68.2.Cursor Swap
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;

    public class MainForm: System.Windows.Forms.Form
    {
        Cursor _handCursor;
        Cursor _embeddedCursor;
        Cursor _smileyCursor;

        private System.Windows.Forms.RadioButton arrowRadioButton;
        private System.Windows.Forms.RadioButton crossRadioButton;
        private System.Windows.Forms.RadioButton defaultRadioButton;
        private System.Windows.Forms.RadioButton handRadioButton;
        private System.Windows.Forms.RadioButton ibeamRadioButton;
        private System.Windows.Forms.RadioButton waitRadioButton;
        private System.Windows.Forms.Button okButton;
        private System.Windows.Forms.RadioButton smileyRadioButton;
        private System.Windows.Forms.RadioButton externalRadioButton;
        private System.Windows.Forms.RadioButton embeddedRadioButton;
        [DllImport("user32.dll", EntryPoint="LoadCursor")]
        private static extern IntPtr InteropLoadCursor(int instance,int resource);

        const int IDC_HAND = 32649;

        public MainForm()
        {
            InitializeComponent();
            IntPtr externalHand = InteropLoadCursor(0, IDC_HAND);
            _handCursor = new Cursor(externalHand);
            _embeddedCursor = new Cursor(this.GetType()"Smiley2.cur");
            _smileyCursor = new Cursor("smiley.cur");
        }
        private void InitializeComponent()
        {
            this.arrowRadioButton = new System.Windows.Forms.RadioButton();
            this.crossRadioButton = new System.Windows.Forms.RadioButton();
            this.defaultRadioButton = new System.Windows.Forms.RadioButton();
            this.handRadioButton = new System.Windows.Forms.RadioButton();
            this.ibeamRadioButton = new System.Windows.Forms.RadioButton();
            this.waitRadioButton = new System.Windows.Forms.RadioButton();
            this.okButton = new System.Windows.Forms.Button();
            this.smileyRadioButton = new System.Windows.Forms.RadioButton();
            this.externalRadioButton = new System.Windows.Forms.RadioButton();
            this.embeddedRadioButton = new System.Windows.Forms.RadioButton();
            this.SuspendLayout();
            // 
            // arrowRadioButton
            // 
            this.arrowRadioButton.Location = new System.Drawing.Point(2464);
            this.arrowRadioButton.Name = "arrowRadioButton";
            this.arrowRadioButton.TabIndex = 0;
            this.arrowRadioButton.Text = "Arrow";
            this.arrowRadioButton.CheckedChanged += new System.EventHandler(this.arrowRadioButton_CheckedChanged);
            // 
            // crossRadioButton
            // 
            this.crossRadioButton.Location = new System.Drawing.Point(2496);
            this.crossRadioButton.Name = "crossRadioButton";
            this.crossRadioButton.TabIndex = 1;
            this.crossRadioButton.Text = "Cross";
            this.crossRadioButton.CheckedChanged += new System.EventHandler(this.crossRadioButton_CheckedChanged);
            // 
            // defaultRadioButton
            // 
            this.defaultRadioButton.Location = new System.Drawing.Point(24128);
            this.defaultRadioButton.Name = "defaultRadioButton";
            this.defaultRadioButton.TabIndex = 2;
            this.defaultRadioButton.Text = "Default";
            this.defaultRadioButton.CheckedChanged += new System.EventHandler(this.defaultRadioButton_CheckedChanged);
            // 
            // handRadioButton
            // 
            this.handRadioButton.Location = new System.Drawing.Point(16064);
            this.handRadioButton.Name = "handRadioButton";
            this.handRadioButton.TabIndex = 4;
            this.handRadioButton.Text = "Hand";
            this.handRadioButton.CheckedChanged += new System.EventHandler(this.handRadioButton_CheckedChanged);
            // 
            // ibeamRadioButton
            // 
            this.ibeamRadioButton.Location = new System.Drawing.Point(16096);
            this.ibeamRadioButton.Name = "ibeamRadioButton";
            this.ibeamRadioButton.TabIndex = 5;
            this.ibeamRadioButton.Text = "I-Beam";
            this.ibeamRadioButton.CheckedChanged += new System.EventHandler(this.ibeamRadioButton_CheckedChanged);
            // 
            // waitRadioButton
            // 
            this.waitRadioButton.Location = new System.Drawing.Point(160128);
            this.waitRadioButton.Name = "waitRadioButton";
            this.waitRadioButton.TabIndex = 6;
            this.waitRadioButton.Text = "Wait Cursor";
            this.waitRadioButton.CheckedChanged += new System.EventHandler(this.waitRadioButton_CheckedChanged);
            // 
            // okButton
            // 
            this.okButton.Location = new System.Drawing.Point(19216);
            this.okButton.Name = "okButton";
            this.okButton.TabIndex = 7;
            this.okButton.Text = "OK";
            this.okButton.Click += new System.EventHandler(this.okButton_Click);
            // 
            // smileyRadioButton
            // 
            this.smileyRadioButton.Location = new System.Drawing.Point(24160);
            this.smileyRadioButton.Name = "smileyRadioButton";
            this.smileyRadioButton.TabIndex = 3;
            this.smileyRadioButton.Text = "Custom- Smiley";
            this.smileyRadioButton.CheckedChanged += new System.EventHandler(this.smileyRadioButton_CheckedChanged);
            // 
            // externalRadioButton
            // 
            this.externalRadioButton.Location = new System.Drawing.Point(160160);
            this.externalRadioButton.Name = "externalRadioButton";
            this.externalRadioButton.TabIndex = 8;
            this.externalRadioButton.Text = "External - Hand";
            this.externalRadioButton.CheckedChanged += new System.EventHandler(this.externalRadioButton_CheckedChanged);
            // 
            // embeddedRadioButton
            // 
            this.embeddedRadioButton.Location = new System.Drawing.Point(24192);
            this.embeddedRadioButton.Name = "embeddedRadioButton";
            this.embeddedRadioButton.Size = new System.Drawing.Size(16824);
            this.embeddedRadioButton.TabIndex = 9;
            this.embeddedRadioButton.Text = "Custom- Embedded Smiley";
            this.embeddedRadioButton.CheckedChanged += new System.EventHandler(this.embeddedRadioButton_CheckedChanged);
            // 
            // mainForm
            // 
            this.AcceptButton = this.okButton;
            this.AutoScaleBaseSize = new System.Drawing.Size(513);
            this.ClientSize = new System.Drawing.Size(292254);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.embeddedRadioButton,
                                                                          this.externalRadioButton,
                                                                          this.smileyRadioButton,
                                                                          this.okButton,
                                                                          this.waitRadioButton,
                                                                          this.ibeamRadioButton,
                                                                          this.handRadioButton,
                                                                          this.defaultRadioButton,
                                                                          this.crossRadioButton,
                                                                          this.arrowRadioButton});
            this.Text = "Cursor Demo";
            this.ResumeLayout(false);

        }
        static void Main() 
        {
            Application.Run(new MainForm());
        }

        private void arrowRadioButton_CheckedChanged(object sender, System.EventArgs e)
        {
            Cursor = Cursors.Arrow;
        }

        private void crossRadioButton_CheckedChanged(object sender, System.EventArgs e)
        {
            Cursor = Cursors.Cross;
        }

        private void defaultRadioButton_CheckedChanged(object sender, System.EventArgs e)
        {
            Cursor = Cursors.Default;
        }

        private void handRadioButton_CheckedChanged(object sender, System.EventArgs e)
        {
            Cursor = Cursors.Hand;
        }

        private void ibeamRadioButton_CheckedChanged(object sender, System.EventArgs e)
        {
            Cursor = Cursors.IBeam;
        }

        private void waitRadioButton_CheckedChanged(object sender, System.EventArgs e)
        {
            Cursor = Cursors.WaitCursor;
        }

        private void okButton_Click(object sender, System.EventArgs e)
        {
            Close();
        }

        private void smileyRadioButton_CheckedChanged(object sender, System.EventArgs e)
        {
            Cursor = _smileyCursor;
        }

        private void externalRadioButton_CheckedChanged(object sender, System.EventArgs e)
        {
            Cursor = _handCursor;
        }

        private void embeddedRadioButton_CheckedChanged(object sender, System.EventArgs e)
        {
            Cursor = _embeddedCursor;
        }
    }
23.68.Cursors
23.68.1.All Cursor constant values
23.68.2.Cursor Swap
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.