源码:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace WindowsFormsSample
{
/// <summary>
/// Summary description for frmSample3.
/// </summary>
[Sample("SourceGrid - Standard features", 3, "Editors and Types")]
public class frmSample3 : System.Windows.Forms.Form
{
private SourceGrid.Grid grid;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public frmSample3()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.grid = new SourceGrid.Grid();
this.SuspendLayout();
//
// grid
//
this.grid.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.grid.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.grid.Location = new System.Drawing.Point(14, 13);
this.grid.Name = "grid";
this.grid.OptimizeMode = SourceGrid.CellOptimizeMode.ForRows;
this.grid.SelectionMode = SourceGrid.GridSelectionMode.Cell;
this.grid.Size = new System.Drawing.Size(512, 366);
this.grid.TabIndex = 0;
this.grid.TabStop = true;
this.grid.ToolTipText = "";
//
// frmSample3
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(540, 391);
this.Controls.Add(this.grid);
this.Name = "frmSample3";
this.Text = "Cell Editors, Specials Cells, Formatting and Image";
this.ResumeLayout(false);
}
#endregion
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
grid.Redim(61, 3);
SourceGrid.Cells.Views.Cell titleModel = new SourceGrid.Cells.Views.Cell();
titleModel.BackColor = Color.SteelBlue;
titleModel.ForeColor = Color.White;
titleModel.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter;
SourceGrid.Cells.Views.Cell captionModel = new SourceGrid.Cells.Views.Cell();
captionModel.BackColor = grid.BackColor;
int currentRow = 0;
#region Base Types
grid[currentRow, 0] = new SourceGrid.Cells.Cell("Base Types");
grid[currentRow, 0].View = titleModel;
grid[currentRow, 0].ColumnSpan = 3;
currentRow++;
//string
grid[currentRow, 0] = new SourceGrid.Cells.Cell("String");
grid[currentRow, 0].View = captionModel;
grid[currentRow, 1] = new SourceGrid.Cells.Cell("String Value", typeof(string));
currentRow++;
//double
grid[currentRow, 0] = new SourceGrid.Cells.Cell("Double");
grid[currentRow, 0].View = captionModel;
grid[currentRow, 1] = new SourceGrid.Cells.Cell(1.5, typeof(double));
currentRow++;
//int
grid[currentRow, 0] = new SourceGrid.Cells.Cell("Int");
grid[currentRow, 0].View = captionModel;
grid[currentRow, 1] = new SourceGrid.Cells.Cell(5, typeof(int));
currentRow++;
//DateTime
grid[currentRow, 0] = new SourceGrid.Cells.Cell("DateTime");
grid[currentRow, 0].View = captionModel;
grid[currentRow, 1] = new SourceGrid.Cells.Cell(DateTime.Now, typeof(DateTime));
currentRow++;
//Boolean
grid[currentRow, 0] = new SourceGrid.Cells.Cell("Boolean");
grid[currentRow, 0].View = captionModel;
grid[currentRow, 1] = new SourceGrid.Cells.Cell(true, typeof(Boolean));
currentRow++;
#endregion
#region Complex Types
grid[currentRow, 0] = new SourceGrid.Cells.Cell("Complex Types");
grid[currentRow, 0].View = titleModel;
grid[currentRow, 0].ColumnSpan = 3;
currentRow++;
//Font
grid[currentRow, 0] = new SourceGrid.Cells.Cell("Font");
grid[currentRow, 0].View = captionModel;
grid[currentRow, 1] = new SourceGrid.Cells.Cell(this.Font, typeof(Font));
currentRow++;
//Cursor
grid[currentRow, 0] = new SourceGrid.Cells.Cell("Cursor");
grid[currentRow, 0].View = captionModel;
grid[currentRow, 1] = new SourceGrid.Cells.Cell(Cursors.Arrow, typeof(Cursor));
currentRow++;
//Point
grid[currentRow, 0] = new SourceGrid.Cells.Cell("Point");
grid[currentRow, 0].View = captionModel;
grid[currentRow, 1] = new SourceGrid.Cells.Cell(new Point(2, 3), typeof(Point));
currentRow++;
//Rectangle
grid[currentRow, 0] = new SourceGrid.Cells.Cell("Rectangle");
grid[currentRow, 0].View = captionModel;
grid[currentRow, 1] = new SourceGrid.Cells.Cell(new Rectangle(100, 100, 200, 200), typeof(Rectangle));
currentRow++;
//Image
grid[currentRow, 0] = new SourceGrid.Cells.Cell("Image");
grid[currentRow, 0].View = captionModel;
grid[currentRow, 1] = new SourceGrid.Cells.Image(Properties.Resources.CalcioSmall);
currentRow++;
//Enum AnchorStyle
grid[currentRow, 0] = new SourceGrid.Cells.Cell("AnchorStyle");
grid[currentRow, 0].View = captionModel;
grid[currentRow, 1] = new SourceGrid.Cells.Cell(AnchorStyles.Bottom, typeof(AnchorStyles));
currentRow++;
//Enum
grid[currentRow, 0] = new SourceGrid.Cells.Cell("Enum");
grid[currentRow, 0].View = captionModel;
grid[currentRow, 1] = new SourceGrid.Cells.Cell(System.Windows.Forms.BorderStyle.Fixed3D, typeof(System.Windows.Forms.BorderStyle));
currentRow++;
//String[]
grid[currentRow, 0] = new SourceGrid.Cells.Cell("String Array");
grid[currentRow, 0].View = captionModel;
string[] strArray = new string[] { "Value 1", "Value 2" };
grid[currentRow, 1] = new SourceGrid.Cells.Cell(strArray, typeof(string[]));
currentRow++;
//Double[]
grid[currentRow, 0] = new SourceGrid.Cells.Cell("Double Array");
grid[currentRow, 0].View = captionModel;
double[] dblArray = new double[] { 1, 0.5, 0.1 };
grid[currentRow, 1] = new SourceGrid.Cells.Cell(dblArray, typeof(double[]));
currentRow++;
#endregion
#region Special Editors
grid[currentRow, 0] = new SourceGrid.Cells.Cell("Special Editors");
grid[currentRow, 0].View = titleModel;
grid[currentRow, 0].ColumnSpan = 3;
currentRow++;
//Time
grid[currentRow, 0] = new SourceGrid.Cells.Cell("Time");
grid[currentRow, 0].View = captionModel;
grid[currentRow, 1] = new SourceGrid.Cells.Cell(DateTime.Now);
grid[currentRow, 1].Editor = new SourceGrid.Cells.Editors.TimePicker();
currentRow++;
//Double Chars Validation
grid[currentRow, 0] = new SourceGrid.Cells.Cell("Double Chars Validation"