Winform控件重写
Winform控件重写
因为最近的项目中越来越多的遇到了比较特殊的一些控件,有时候我们自己封装一下可能更加方便我们的使用,下面是我们项目中用到的,简单做一个记录。
TextBox控件重写
主要的控制代码都在WndProc中
只能输入数字,包括小数
public class FloatNumTextBox : TextBox
{
protected override void WndProc(ref Message m)
{
int WM_CHAR = 0x0102;
if (m.Msg == WM_CHAR)
{
if (((char)m.WParam >= '') && ((char)m.WParam <= '') ||
(int)m.WParam == (int)Keys.Back || (int)m.WParam == (int)Keys.Delete)
{
base.WndProc(ref m);
}
}
else
{
base.WndProc(ref m);
}
}
}
只能输入整数
public class IntNumTextBox :TextBox
{
protected override void WndProc(ref Message m)
{
int WM_CHAR = 0x0102;
if (m.Msg == WM_CHAR)
{
if (((char)m.WParam >= '') && ((char)m.WParam <= '') ||
(int)m.WParam == (int)Keys.Back)
{
base.WndProc(ref m);
}
}
else
{
base.WndProc(ref m);
}
}
}
DataGridFView重写
DataGridView的主要代码是因为有很多的样式不需要再重新设置了,这样可以只修改一处,即可修改整个项目中的所有DataGridView样式的显示,主要的代码起始都是在构造函数中完成
public class MydataGridview :DataGridView
{
public MydataGridview():base()
{
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle();
this.AutoGenerateColumns = false;
this.AllowUserToAddRows = false;
this.AllowUserToDeleteRows = false;
this.AllowUserToResizeColumns = false;
this.AllowUserToResizeRows = false;
dataGridViewCellStyle1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)()))), ((int)(((byte)()))), ((int)(((byte)()))));
this.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle1;
this.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
this.BackgroundColor = System.Drawing.Color.White;
this.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.Single;
dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)()))), ((int)(((byte)()))), ((int)(((byte)()))));
dataGridViewCellStyle2.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)()));
dataGridViewCellStyle2.ForeColor = System.Drawing.Color.Navy;
dataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
this.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle2;
this.ColumnHeadersHeight = ;
this.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle3.BackColor = System.Drawing.SystemColors.Window;
dataGridViewCellStyle3.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)()));
dataGridViewCellStyle3.ForeColor = System.Drawing.SystemColors.ControlText;
dataGridViewCellStyle3.SelectionBackColor = System.Drawing.Color.FromArgb(((int)(((byte)()))), ((int)(((byte)()))), ((int)(((byte)()))));
dataGridViewCellStyle3.SelectionForeColor = System.Drawing.SystemColors.ControlText;
dataGridViewCellStyle3.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
this.DefaultCellStyle = dataGridViewCellStyle3;
this.EnableHeadersVisualStyles = false;
this.GridColor = System.Drawing.Color.FromArgb(((int)(((byte)()))), ((int)(((byte)()))), ((int)(((byte)()))));
this.Location = new System.Drawing.Point(, ); this.RowHeadersVisible = false;
this.RowTemplate.Height = ;
this.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
this.Size = new System.Drawing.Size(, ); }
}
Winform控件重写的更多相关文章
- 玩转控件:重写/重绘Dev中MessageBox弹窗控件
很久没有更新博客了,本想着直接发一篇<手撕ERP>系列,从控件重写.重绘,到框架搭建,再到部分模块实现+业务的.但是每次动手的时候,都觉得难以下手.直接从数据库设计开始吧,模块设计还没定下 ...
- 浅谈Winform控件开发(一):使用GDI+美化基础窗口
写在前面: 本系列随笔将作为我对于winform控件开发的心得总结,方便对一些读者在GDI+.winform等技术方面进行一个入门级的讲解,抛砖引玉. 别问为什么不用WPF,为什么不用QT.问就是懒, ...
- 在WPF中使用WinForm控件方法
1. 首先添加对如下两个dll文件的引用:WindowsFormsIntegration.dll,System.Windows.Forms.dll. 2. 在要使用WinForm控 ...
- WPF 调用WinForm控件
WPF可以使用WindowsFormsHost控件做为容器去显示WinForm控件,类似的用法网上到处都是,就是拖一个WindowsFormsHost控件winHost1到WPF页面上,让后设置win ...
- WinForm控件TreeView 只部分节点显示 CheckBox
WinForm控件TreeView 只部分节点显示 CheckBox 用过asp.net的应该知道,要在treeview中实现上述功能可以使用ShowCheckBox 属性指定那些节点显示check ...
- 通过WinForm控件创建的WPF控件无法输入的问题
今天把写的一个WPF程序发布到别的机器上执行,发现一个比较奇怪的问题:在那个机器上用英文输入法无法输入数字,非要切换到中文输入法才行:但在我的机器上却是好好的. 最开始以为是输入法的问题,弄了好一阵子 ...
- c#Winform控件总结
1. C# WinForm控件.自定义控件整理(大全) (http://www.cnblogs.com/top5/archive/2010/04/29/1724039.html) 2. c#窗体控件用 ...
- 在WPF中调用Winform控件
最近在项目中用到了人脸识别和指纹识别,需要调用外部设备和接口,这里就用到了在WPF中调用Winform控件. 第一步,添加程序集引用.System.Windows.Forms和WindowsForms ...
- C# 扩展方法奇思妙用高级篇六:WinForm 控件选择器
在Web开发中,jQuery提供了功能异常强大的$选择器来帮助我们获取页面上的对象.但在WinForm中,.Net似乎没有这样一个使用起来比较方便的选择器.好在我们有扩展方法,可以很方便的打造一个. ...
随机推荐
- 对Google cloud platform 做了点研究
Google也推出了云计算基础服务, 加上微软Azure,亚马逊AWS, 都齐活了. 下面是研究了一下对其的一个初步了解. 计算: Compute Engine IaaS平台,提供VM,操作灵 ...
- java 锁3
先谈线程的状态: 具体来说有, NEW. Running. Blocked.此状态的线程阻塞,它正在等待监视器锁——等待另外一个线程释放锁(通俗说就是等它执行完synchronized了的方法/代码块 ...
- jQuery不支持hashchange事件?
$(window) .bind( 'hashchange', onHashchange ) .trigger( 'hashchange' ); jQuery版本是1.9.1的,去源码里没找到hashc ...
- Java-练习方法之冒泡排序
1. 实现冒泡排序算法. int[] daxiao=new int[]{45,23,7,75,87,34,98,3,13}; for(int i=0;i<8;i++) { for(int j=i ...
- Atitit 团队建设的知识管理
Atitit 团队建设的知识管理 1.1. 要遵循"知识积累--创造--应用--形成知识平台--再积累--再创造--再应用--形成新的知识平台"的循环过程.1 1.2. 显性知识包 ...
- iOS-UICollectionView
1--------------------------------------------------------------------------------------------------- ...
- java容器详细解析
前言:在java开发中我们肯定会大量的使用集合,在这里我将总结常见的集合类,每个集合类的优点和缺点,以便我们能更好的使用集合.下面我用一幅图来表示 其中淡绿色的表示接口,红色的表示我们经常使用的类. ...
- SQL Server的日期和时间类型
Sql Server使用 Date 表示日期,time表示时间,使用datetime和datetime2表示日期和时间. 1,秒的精度是指使用多少位小数表示秒 DateTime数据类型秒的精度是3,D ...
- KendoUI系列:MultiSelect
1.基本使用 1>.创建Input <link href="@Url.Content("~/Content/kendo/2014.1.318/kendo.common. ...
- 专为设计师而写的GitHub快速入门教程
专为设计师而写的GitHub快速入门教程 来源: 伯乐在线 作者:Kevin Li 原文出处: Kevin Li 在互联网行业工作的想必都多多少少听说过GitHub的大名,除了是最大的开源项目 ...