本文整理汇总了C#中System.Windows.Forms.Cursor类的典型用法代码示例。如果您正苦于以下问题:C# Cursor类的具体用法?C# Cursor怎么用?C# Cursor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Cursor类属于System.Windows.Forms命名空间,在下文中一共展示了Cursor类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ArrayList
// The basic Customer class.
public class Customer : System.Object
{
private string custName = "";
protected ArrayList custOrders = new ArrayList();
public Customer(string customername)
{
this.custName = customername;
}
public string CustomerName
{
get{return this.custName;}
set{this.custName = value;}
}
public ArrayList CustomerOrders
{
get{return this.custOrders;}
}
} // End Customer class
// The basic customer Order class.
public class Order : System.Object
{
private string ordID = "";
public Order(string orderid)
{
this.ordID = orderid;
}
public string OrderID
{
get{return this.ordID;}
set{this.ordID = value;}
}
} // End Order class
// Create a new ArrayList to hold the Customer objects.
private ArrayList customerArray = new ArrayList();
private void FillMyTreeView()
{
// Add customers to the ArrayList of Customer objects.
for(int x=0; x<1000; x++)
{
customerArray.Add(new Customer("Customer" + x.ToString()));
}
// Add orders to each Customer object in the ArrayList.
foreach(Customer customer1 in customerArray)
{
for(int y=0; y<15; y++)
{
customer1.CustomerOrders.Add(new Order("Order" + y.ToString()));
}
}
// Display a wait cursor while the TreeNodes are being created.
Cursor.Current = new Cursor("MyWait.cur");
// Suppress repainting the TreeView until all the objects have been created.
treeView1.BeginUpdate();
// Clear the TreeView each time the method is called.
treeView1.Nodes.Clear();
// Add a root TreeNode for each Customer object in the ArrayList.
foreach(Customer customer2 in customerArray)
{
treeView1.Nodes.Add(new TreeNode(customer2.CustomerName));
// Add a child treenode for each Order object in the current Customer object.
foreach(Order order1 in customer2.CustomerOrders)
{
treeView1.Nodes[customerArray.IndexOf(customer2)].Nodes.Add(
new TreeNode(customer2.CustomerName + "." + order1.OrderID));
}
}
// Reset the cursor to the default for all controls.
Cursor.Current = Cursors.Default;
// Begin repainting the TreeView.
treeView1.EndUpdate();
}
示例2: Main
//引入命名空间
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 a bitmap
// 1. Add a new cursor file to your project:
// Project->Add New Item->General->Cursor File
// --- 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 Resources"
// 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");
}
}
}
示例3: new Cursor(String cursorFile)
//引入命名空间
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
public class Form1 : Form {
public Form1() {
this.SuspendLayout();
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 268);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove);
this.ResumeLayout(false);
}
private void Form1_MouseMove(object sender, MouseEventArgs e) {
Point p = new Point(e.X, e.Y);
Rectangle r;
if (new Rectangle(0, 0, 100, 100).Contains(p))
this.Cursor = new Cursor("MyCursor.cur");
else if (new Rectangle(100, 0, 100, 100).Contains(p))
this.Cursor = Cursors.Hand;
else if (new Rectangle(0, 100, 100, 100).Contains(p))
this.Cursor = Cursors.VSplit;
else if (new Rectangle(100, 100, 100, 100).Contains(p))
this.Cursor = Cursors.UpArrow;
else
this.Cursor = Cursors.Default;
}
private void Form1_Paint(object sender, PaintEventArgs e) {
Graphics g = e.Graphics;
g.FillRectangle(Brushes.Blue, 0, 0, 100, 100);
g.FillRectangle(Brushes.Red, 100, 0, 100, 100);
g.FillRectangle(Brushes.Yellow, 0, 100, 100, 100);
g.FillRectangle(Brushes.Green, 100, 100, 100, 100);
}
static void Main() {
Application.EnableVisualStyles();
Application.Run(new Form1());
}
}