using System;
using System.Windows.Forms;
using System.Drawing;

namespace HISClinic.UIProcess.ColumnStyles
{
	/// <summary>
	/// DataGridTextColumnEx 的摘要说明。
	/// </summary>
	public class DataGridTextBoxColumnEx:DataGridTextBoxColumn
	{
		public DataGridTextBoxColumnEx():base()
		{
			//
			// TODO: 在此处添加构造函数逻辑
			//
		}

		protected override void Edit(CurrencyManager source, int rowNum, Rectangle bounds, bool readOnly, string instantText, bool cellIsVisible)
		{
			//
		}

		protected override void Paint(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, CurrencyManager source, int rowNum, System.Drawing.Brush backBrush, System.Drawing.Brush foreBrush, bool alignToRight)
		{
			object temp=GetColumnValueAtRow(source,rowNum);            
			string Value=temp.ToString();

			StringFormat sf=new StringFormat();
				
			//文字水平对齐方式
			switch(this.Alignment)
			{
				case HorizontalAlignment.Left:
					sf.Alignment=StringAlignment.Near;
					break;

				case HorizontalAlignment.Center:
					sf.Alignment=StringAlignment.Center;
					break;

				case HorizontalAlignment.Right:
					sf.Alignment=StringAlignment.Far;
					break;
			}
                
			//对文字的位置做一下修正,以便和.NET本身自带的ColumnStyle输出的文字看起来水平对齐
			Rectangle rect=new Rectangle(bounds.Left+2,bounds.Top+2,bounds.Width,bounds.Height-2);				

			//如果当前行为所选行，用高亮颜色输出结果和背景
			if(rowNum == this.DataGridTableStyle.DataGrid.CurrentRowIndex)
			{
				g.FillRectangle(new SolidBrush(this.DataGridTableStyle.DataGrid.SelectionBackColor),bounds);
				g.DrawString(Value,this.DataGridTableStyle.DataGrid.Font,new SolidBrush(this.DataGridTableStyle.DataGrid.SelectionForeColor),rect,sf);					
			}
			else
			{
				g.FillRectangle(backBrush,bounds);
				g.DrawString(Value,this.DataGridTableStyle.DataGrid.Font,foreBrush,rect,sf);
			}			
		}
	}
}
