📄 graphiccolumn.cs
字号:
///GeoCon, free tool to create gml & svg from gis files.
///Copyright(C) 2005 Amri Rosyada
///Distributed under GNU-LGPL, see a copy of the license in root directory
using System;
using System.Data;
using System.Windows.Forms;
using System.Drawing;
using GeoCon.Classification;
namespace GeoCon.util
{
/// <summary>
/// Column Style for displaying Bin Symbol in datagrid.
/// </summary>
public class DataGridGraphicColumn : DataGridColumnStyle
{
private Button button=new Button();
private CurrencyManager cm;
private int iCurrentRow;
/// <summary>
/// Constructs new DataGridGraphicColumn
/// </summary>
public DataGridGraphicColumn()
{
button.BackColor=Color.Transparent;
button.FlatStyle=FlatStyle.Popup;
button.Leave +=new EventHandler(button_Leave);
button.Click +=new EventHandler(button_Click);
//button.Paint +=new PaintEventHandler(button_Paint);
}
/// <summary>
/// Refresh column drawing.
/// </summary>
public void updateCurrencyManager()
{
cm =(CurrencyManager) this.DataGridTableStyle.DataGrid.BindingContext[this.DataGridTableStyle.DataGrid.DataSource];
this.button.Hide();
this.Invalidate();
}
#region must override members
protected override void Edit(CurrencyManager source, int rowNum, Rectangle bounds, bool readOnly, string instantText, bool cellIsVisible)
{
if(readOnly || cellIsVisible==false) return;
cm=source;
iCurrentRow = rowNum;
button.Parent=this.DataGridTableStyle.DataGrid;
Rectangle rect=this.DataGridTableStyle.DataGrid.GetCurrentCellBounds();
button.Location=rect.Location;
button.Size=new Size(rect.Width, rect.Height);
button.BringToFront();
button.Show();
button.Focus();
this.DataGridTableStyle.DataGrid.Scroll+=new EventHandler(DataGrid_Scroll);
}
private void DataGrid_Scroll(object sender, EventArgs e)
{
this.button.Hide();
}
protected override void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum)
{
cm=source;
Bin b = (Bin)cm.List[rowNum];
b.Symbol.DrawIcon(g,bounds);
}
protected override void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, bool alignToRight)
{
cm=source;
Bin b = (Bin)cm.List[rowNum];
b.Symbol.DrawIcon(g,bounds);
}
protected override void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, Brush backBrush, Brush foreBrush, bool alignToRight)
{
cm=source;
g.FillRectangle(backBrush,bounds);
Bin b = (Bin)cm.List[rowNum];
b.Symbol.DrawIcon(g,bounds);
}
protected override void Abort(int rowNum)
{
}
protected override bool Commit(CurrencyManager dataSource, int rowNum)
{
this.ConcedeFocus();
return true;
}
protected override int GetMinimumHeight(){return 0;}
protected override int GetPreferredHeight(Graphics g, object value) {return 20;}
protected override Size GetPreferredSize(Graphics g, object value){return new Size(50,20);}
#endregion
#region optional override members
protected override void SetColumnValueAtRow(CurrencyManager source, int rowNum, object Value)
{
base.SetColumnValueAtRow (source, rowNum, Value);
}
protected override object GetColumnValueAtRow(CurrencyManager source, int rowNum)
{
return source.List[rowNum];
}
protected override void UpdateUI(CurrencyManager source, int rowNum, string instantText)
{
base.UpdateUI (source, rowNum, instantText);
}
// protected override void ConcedeFocus()
// {
// this.button.Hide();
// this.Invalidate();
// base.ConcedeFocus ();
// }
// void Dispose()
// {
// button.Dispose();
// if(!FStyle.IsDisposed) FStyle.Dispose();
// Dispose(true);
// GC.SuppressFinalize(this);
// }
// ~DataGridGraphicColumn()
// {
// Dispose(false);
// }
#endregion
#region button event handler
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button_Leave(object sender, EventArgs e)
{
this.button.Hide();
this.Invalidate();
}
private GeoCon.StyleForm FStyle=new StyleForm();
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button_Click(object sender, EventArgs e)
{
if(FStyle.IsDisposed) FStyle = new StyleForm();
FStyle.Owner=MainForm.ActiveForm;
FStyle.CurrencyMgr = cm;
FStyle.Show();
FStyle.BringToFront();
//TODO : re-translate the icon to reflect clicked button
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -