⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ydatagrid.cs

📁 一个通用的数据库访问层
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace YariSoft.Windows.Conrols
{
	public class YDataGrid : System.Windows.Forms.DataGrid
	{
		#region Events
		public delegate bool YKeyEventHandler( ref Message msg, Keys keyData );
		public event YKeyEventHandler YOnKeyDown;		
		#endregion

		#region Local variables
		private System.ComponentModel.Container components = null;
		private const Int32 SRCCOPY = 0xCC0020;
		#endregion

		#region Constructor/Destructor
		public YDataGrid()
		{
			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 );
		}
		#endregion

		#region Component 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()
		{
			components = new System.ComponentModel.Container();
		}
		#endregion

		#region Public functions
		public void ScrollToRow( int RowID )
		{
			if( this.DataSource != null ){
				this.GridVScrolled( this, new ScrollEventArgs(ScrollEventType.LargeIncrement, RowID ) );
			}
		}

		public Bitmap GetGridImage()
		{
			Graphics graphic = this.CreateGraphics();
			Size s = this.Size;
			Bitmap memImage = new Bitmap(s.Width, s.Height, graphic);
			Graphics memGraphic = Graphics.FromImage(memImage);
			IntPtr dc1 = graphic.GetHdc();
			IntPtr dc2 = memGraphic.GetHdc();
			BitBlt(dc2, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, dc1, 0, 0, SRCCOPY);
			graphic.ReleaseHdc(dc1);
			memGraphic.ReleaseHdc(dc2);
			graphic.Dispose();
			return memImage;
		}
		#endregion

		#region Protected variables
		protected override bool ProcessCmdKey( ref Message msg, Keys keyData )
		{
			if( this.YOnKeyDown != null ){
				if( this.YOnKeyDown( ref msg, keyData ) ){
					return true;	
				}
			}
			return base.ProcessCmdKey( ref msg, keyData );
		}
		#endregion

		#region Private functions
		[DllImport("gdi32.dll")]
		private static extern bool BitBlt(
			IntPtr hdcDest, // handle to destination DC
			int nXDest,		// x-coord of destination upper-left corner
			int nYDest,		// y-coord of destination upper-left corner
			int nWidth,		// width of destination rectangle
			int nHeight,	// height of destination rectangle
			IntPtr hdcSrc,	// handle to source DC
			int nXSrc,		// x-coordinate of source upper-left corner
			int nYSrc,		// y-coordinate of source upper-left corner
			System.Int32 dwRop // raster operation code
		);
		#endregion
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -