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似乎没有这样一个使用起来比较方便的选择器.好在我们有扩展方法,可以很方便的打造一个. ...
随机推荐
- Atitit 热更新资源管理器 自动更新管理器 功能设计
Atitit 热更新资源管理器 自动更新管理器 功能设计 · 多线程并行下载支持 · 两层进度统计信息:文件级以及字节级 · Zip压缩文件支持 · 断点续传 · 详细的错误报告 · 文件下载失败重试 ...
- fir.im Weekly - 如何写出零 bug 的代码
神兽护体,代码无bug.经常看到代码注释的各种形状,这是一种程序员情怀.那么,如何能写出零 Bug 的代码呢,来看看@码农翻身 的这篇手册--零Bug的代码是怎么炼成的. 写零 Bug 一定少不了代码 ...
- asp.net 站点重启
有时一些特殊情况需要重启站点,在System.Web.dll程序集下HttpRuntime类下有一个静态方法UnloadAppDomain,使用这个方法可以重启站点: protected void b ...
- react5 事件 satate
<body><!-- React 真实 DOM 将会插入到这里 --><div id="example"></div> <!- ...
- WPF入门教程系列六——布局介绍与Canvas(一)
从这篇文章开始是对WPF中的界面如何布局做一个较简单的介绍,大家都知道:UI是做好一个软件很重要的因素,如果没有一个漂亮的UI,功能做的再好也无法吸引很多用户使用,而且没有漂亮的界面,那么普通用户会感 ...
- jQuery LigerUI 最新版压缩包(含chm帮助文档、源码、donet权限示例)
jQuery LigerUI 最新版压缩包 http://download.csdn.net/download/heyin12345/4680593 jQuery LigerUI 最新版压缩包(含ch ...
- 谈谈java的运行机制
1.高级语言的运行机制 我们编程都是用的高级语言(写汇编和机器语言的大牛们除外),计算机不能直接理解高级语言,只能理解和运行机器语言,所以必须要把高级语言翻译成机器语言,计算机才能运行高级语言所编写的 ...
- Warning: Null value is eliminated by an aggregate or other SET operation.
Null 值会被聚合函数忽略,默认情况下,Sql Server会给出Warning: Warning: Null value is eliminated by an aggregate or othe ...
- 在Windows平台上安装Node.js及NPM模块管理
1. 下载Node.js官方Windows版程序:http://nodejs.org/#download 从0.6.1开始,Node.js在Windows平台上提供了两种安装方式,一是.MSI安 ...
- 动画animation的三个应用(漂浮的白云、旋转的星球、正方体合成)
× 目录 [1]漂浮的白云 [2]旋转的星球 [3]正方体合成 前面的话 前面介绍过动画animation的详细用法,本文主要介绍动画animation的三个效果 漂浮的白云 [效果演示] [简要介绍 ...