您的位置:首页 > 其它

sourcegrid 应用实例(全部来自官网下载的例子)——Real Grid basic (custom header, alternate backcolor)

2011-06-13 22:12 956 查看


源码:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace WindowsFormsSample
{
/// <summary>
/// Summary description for frmSample14.
/// </summary>
[Sample("SourceGrid - Basic concepts", 28, "Real Grid basic (custom header, alternate backcolor)")]
public class frmSample28 : System.Windows.Forms.Form
{
private SourceGrid.Grid grid1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public frmSample28()
{
//
// 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.grid1 = new SourceGrid.Grid();
this.SuspendLayout();
//
// grid1
//
this.grid1.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.grid1.Location = new System.Drawing.Point(10, 9);
this.grid1.Name = "grid1";
this.grid1.OptimizeMode = SourceGrid.CellOptimizeMode.ForRows;
this.grid1.SelectionMode = SourceGrid.GridSelectionMode.Cell;
this.grid1.Size = new System.Drawing.Size(273, 254);
this.grid1.TabIndex = 0;
this.grid1.TabStop = true;
this.grid1.ToolTipText = "";
//
// frmSample28
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 271);
this.Controls.Add(this.grid1);
this.Name = "frmSample28";
this.Text = "Basic Grid";
this.ResumeLayout(false);

}
#endregion

protected override void OnLoad(EventArgs e)
{
base.OnLoad (e);

//Border
DevAge.Drawing.BorderLine border = new DevAge.Drawing.BorderLine(Color.DarkKhaki, 1);
DevAge.Drawing.RectangleBorder cellBorder = new DevAge.Drawing.RectangleBorder(border, border);

//Views
CellBackColorAlternate viewNormal = new CellBackColorAlternate(Color.Khaki, Color.DarkKhaki);
viewNormal.Border = cellBorder;
CheckBoxBackColorAlternate viewCheckBox = new CheckBoxBackColorAlternate(Color.Khaki, Color.DarkKhaki);
viewCheckBox.Border = cellBorder;

//ColumnHeader view
SourceGrid.Cells.Views.ColumnHeader viewColumnHeader = new SourceGrid.Cells.Views.ColumnHeader();
DevAge.Drawing.VisualElements.ColumnHeader backHeader = new DevAge.Drawing.VisualElements.ColumnHeader();
backHeader.BackColor = Color.Maroon;
backHeader.Border = DevAge.Drawing.RectangleBorder.NoBorder;
viewColumnHeader.Background = backHeader;
viewColumnHeader.ForeColor = Color.White;
viewColumnHeader.Font = new Font("Comic Sans MS", 10, FontStyle.Underline);

//Editors
SourceGrid.Cells.Editors.TextBox editorString = new SourceGrid.Cells.Editors.TextBox(typeof(string));
SourceGrid.Cells.Editors.TextBoxUITypeEditor editorDateTime = new SourceGrid.Cells.Editors.TextBoxUITypeEditor(typeof(DateTime));

//Create the grid
grid1.BorderStyle = BorderStyle.FixedSingle;

grid1.ColumnsCount = 3;
grid1.FixedRows = 1;
grid1.Rows.Insert(0);

SourceGrid.Cells.ColumnHeader columnHeader;

columnHeader = new SourceGrid.Cells.ColumnHeader("String");
columnHeader.View = viewColumnHeader;
grid1[0,0] = columnHeader;

columnHeader = new SourceGrid.Cells.ColumnHeader("DateTime");
columnHeader.View = viewColumnHeader;
grid1[0,1] = columnHeader;

columnHeader = new SourceGrid.Cells.ColumnHeader("CheckBox");
columnHeader.View = viewColumnHeader;
grid1[0,2] = columnHeader;

for (int r = 1; r < 10; r++)
{
grid1.Rows.Insert(r);

grid1[r,0] = new SourceGrid.Cells.Cell("Hello " + r.ToString());
grid1[r,0].Editor = editorString;

grid1[r,1] = new SourceGrid.Cells.Cell(DateTime.Today);
grid1[r,1].Editor = editorDateTime;

grid1[r,2] = new SourceGrid.Cells.CheckBox(null, true);

grid1[r,0].View = viewNormal;
grid1[r,1].View = viewNormal;
grid1[r,2].View = viewCheckBox;
}

grid1.AutoSizeCells();
}

private class CellBackColorAlternate : SourceGrid.Cells.Views.Cell
{
public CellBackColorAlternate(Color firstColor, Color secondColor)
{
FirstBackground = new DevAge.Drawing.VisualElements.BackgroundSolid(firstColor);
SecondBackground = new DevAge.Drawing.VisualElements.BackgroundSolid(secondColor);
}

private DevAge.Drawing.VisualElements.IVisualElement mFirstBackground;
public DevAge.Drawing.VisualElements.IVisualElement FirstBackground
{
get { return mFirstBackground; }
set { mFirstBackground = value; }
}

private DevAge.Drawing.VisualElements.IVisualElement mSecondBackground;
public DevAge.Drawing.VisualElements.IVisualElement SecondBackground
{
get { return mSecondBackground; }
set { mSecondBackground = value; }
}

protected override void PrepareView(SourceGrid.CellContext context)
{
base.PrepareView(context);

if (Math.IEEERemainder(context.Position.Row, 2) == 0)
Background = FirstBackground;
else
Background = SecondBackground;
}
}

private class CheckBoxBackColorAlternate : SourceGrid.Cells.Views.CheckBox
{
public CheckBoxBackColorAlternate(Color firstColor, Color secondColor)
{
FirstBackground = new DevAge.Drawing.VisualElements.BackgroundSolid(firstColor);
SecondBackground = new DevAge.Drawing.VisualElements.BackgroundSolid(secondColor);
}

private DevAge.Drawing.VisualElements.IVisualElement mFirstBackground;
public DevAge.Drawing.VisualElements.IVisualElement FirstBackground
{
get { return mFirstBackground; }
set { mFirstBackground = value; }
}

private DevAge.Drawing.VisualElements.IVisualElement mSecondBackground;
public DevAge.Drawing.VisualElements.IVisualElement SecondBackground
{
get { return mSecondBackground; }
set { mSecondBackground = value; }
}

protected override void PrepareView(SourceGrid.CellContext context)
{
base.PrepareView(context);

if (Math.IEEERemainder(context.Position.Row, 2) == 0)
Background = FirstBackground;
else
Background = SecondBackground;
}

}

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐