Csharp/CSharp Tutorial/GUI Windows Forms/Cursors

Материал из .Net Framework эксперт
Версия от 12:15, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

All Cursor constant values

using System;
using System.Drawing;
using System.Windows.Forms;
   
class MouseCursorsProperty: Form
{
     Label[] acntl = new Label[28];
   
     public static void Main()
     {
          Application.Run(new MouseCursorsProperty());
     }
     public MouseCursorsProperty()
     {
          Cursor[] acursor = 
          { 
               Cursors.AppStarting, Cursors.Arrow,       Cursors.Cross, 
               Cursors.Default,     Cursors.Hand,        Cursors.Help,     
               Cursors.HSplit,      Cursors.IBeam,       Cursors.No, 
               Cursors.NoMove2D,    Cursors.NoMoveHoriz, Cursors.NoMoveVert,
               Cursors.PanEast,     Cursors.PanNE,       Cursors.PanNorth,
               Cursors.PanNW,       Cursors.PanSE,       Cursors.PanSouth,
               Cursors.PanSW,       Cursors.PanWest,     Cursors.SizeAll,
               Cursors.SizeNESW,    Cursors.SizeNS,      Cursors.SizeNWSE,
               Cursors.SizeWE,      Cursors.UpArrow,     Cursors.VSplit, 
               Cursors.WaitCursor
          };
          string[] astrCursor = 
          { 
               "AppStarting",       "Arrow",             "Cross",       
               "Default",           "Hand",              "Help",     
               "HSplit",            "IBeam",             "No",          
               "NoMove2D",          "NoMoveHoriz",       "NoMoveVert",
               "PanEast",           "PanNE",             "PanNorth",    
               "PanNW",             "PanSE",             "PanSouth",
               "PanSW",             "PanWest",           "SizeAll",     
               "SizeNESW",          "SizeNS",            "SizeNWSE",
               "SizeWE",            "UpArrow",           "VSplit",      
               "WaitCursor" 
          };
   
          Text = "Mouse Cursors Using Cursor Property";
   
          for (int i = 0; i < 28; i++)
          {
               acntl[i] = new Label();
               acntl[i].Parent = this;
               acntl[i].Text = astrCursor[i];
               acntl[i].Cursor = acursor[i]; 
               acntl[i].BorderStyle = BorderStyle.FixedSingle;
          }
          OnResize(EventArgs.Empty);
     }
     protected override void OnResize(EventArgs ea)
     {
          for (int i = 0; i < acntl.Length; i++)
          {
               acntl[i].Bounds = Rectangle.FromLTRB(
                                        (i % 4    ) * ClientSize.Width  / 4, 
                                        (i / 4    ) * ClientSize.Height / 7,
                                        (i % 4 + 1) * ClientSize.Width  / 4, 
                                        (i / 4 + 1) * ClientSize.Height / 7);
          }
     }
}

Cursor Swap

using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
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(24, 64);
            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(24, 96);
            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(24, 128);
            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(160, 64);
            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(160, 96);
            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(160, 128);
            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(192, 16);
            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(24, 160);
            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(160, 160);
            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(24, 192);
            this.embeddedRadioButton.Name = "embeddedRadioButton";
            this.embeddedRadioButton.Size = new System.Drawing.Size(168, 24);
            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(5, 13);
            this.ClientSize = new System.Drawing.Size(292, 254);
            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;
        }
    }