Volunteer .NET Evangelist
A well oiled machine can’t run efficiently, if you grease it with water.
::
首页
:: ::
联系
::
订阅
::
管理
CreateParams Is Pretty Cool!
Posted on 2006-04-29 23:30
Sheva
阅读(1618)
评论(7)
编辑
收藏
所属分类:
Windows Forms
Probably I've been in the WPF world for so long that I need to try something different, yesterday, I come across a
Channel9 forum thread
on how to use windows forms' Control.CreateParams property, which give me some light on how to customize the style of classical Win32 window.
First thing I plan to do is make the System.Windows.Forms.Form window support dropshadow, then I write a custom NumberBox control which only accepts numbers, traditionaly if you want a TexBox to only accept numbers, you can hookup it's KeyDown event to verify the actual keyboard input, in this post, I will show another way to do it, aka using edit control style as the following code demonstrates:
using
System;
using
System.Windows.Forms;
using
System.Runtime.InteropServices;
namespace
CreateParamsDemo
{
public
partial
class
MyCustomForm : Form
{
private
static
Int32 CS_DROPSHADOW
=
0x00020000
;
public
MyCustomForm()
{
InitializeComponent();
NumberBox box
=
new
NumberBox();
box.Multiline
=
true
;
box.Dock
=
DockStyle.Fill;
this
.Controls.Add(box);
}
protected
override
CreateParams CreateParams
{
get
{
CreateParams parameters
=
base
.CreateParams;
parameters.ClassStyle
|=
CS_DROPSHADOW;
return
parameters;
}
}
}
public
class
NumberBox : TextBox
{
private
static
Int32 ES_NUMBER
=
0x2000
;
protected
override
CreateParams CreateParams
{
get
{
CreateParams parameters
=
base
.CreateParams;
parameters.Style
|=
ES_NUMBER;
return
parameters;
}
}
}
}
Now, the code is up and ready for running, here comes the screenshot:
Please pay closer attention to the shadow around the window border, you will get the dropshadow for the window, and if you press any key except number keys, a balloon tool tip will show up, saying "Unacceptable Character", the implementation is quite simple, but you can actually get your job done quickly, you know, sometimes, simple approach is the best:)
Feedback
#1楼
回复
引用
2006-04-30 00:07 by
web [未注册用户]
我觉得还是用中文吧?
#2楼
回复
引用
查看
2006-04-30 08:21 by
菌哥
外文是用来学习外国的技术的,其余的请用中文,支持中文...
#3楼
回复
引用
查看
2006-04-30 08:26 by
维生素C.NET
make the System.Windows.Forms.Form window support dropshow
这个dropShow是Dropshadow吗?
#4楼
回复
引用
2006-04-30 08:29 by
Yeah [未注册用户]
YEah, this thread is pretty coool~ ,thx
#5楼
回复
引用
查看
2006-04-30 08:54 by
Dflying Chen
@web
@菌哥
确实,在中文社区还是写中文好一点
#6楼
回复
引用
2006-04-30 09:33 by
gyf19 [未注册用户]
英语不好!!看不懂好文章,努力学英语
#7楼
回复
引用
2007-08-21 13:50 by
jesan [未注册用户]
用了createparmas之后,是可以达到改变窗体的效果,但窗体周围会出现一条框,不知怎样才可以消除,谢谢,
新用户注册
刷新评论列表
标题
姓名
主页
Email
(博主才能看到)
验证码
*
看不清,换一张
[
登录
][
注册
]
内容(请不要发表任何与政治相关的内容)
博客园首页
新闻频道
社区
小组
博问
网摘
闪存
Remember Me?
登录
使用高级评论
新用户注册
返回页首
恢复上次提交
[使用Ctrl+Enter键可以直接提交]
该文被作者在 2006-04-30 13:21 编辑过
成果网帮您增加网站收入
相关文章:
XmlSerializerFactory Is Pretty Cool[转]
XmlSerializerFactory Is Pretty Cool[转]
重载 CreateParams 方法[2]: 重载 TForm.CreateParams 方法的几个
XmlnsDefinitionAttribute Is Pretty Nifty
重载 CreateParams 方法[1]: 从一个例子开始(取消窗口最大化、最小化按钮的三种方法)
Cool SMIL
相关链接:
最新IT新闻:
淘宝与微软总部达成首次合作 Silverlight加入店铺
苹果9日发布iTunes 8、iPhone 2.1和第四代iPod Nano
微软出品8GB蓝色和120GB Zune播放器
千亿美元市值榜:微软居首移动第二 诺基亚退榜
Google申请“海上数据中心”专利 可能付诸行动
Powered by:
博客园
Copyright © Sheva
日历
<
2006年4月
>
日
一
二
三
四
五
六
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
与我互动
给我发短消息
搜索
常用链接
我的随笔
我的空间
我的短信
我的评论
更多链接
我的参与
我的新闻
最新评论
我的标签
留言簿
(6)
给我留言
查看私人留言
随笔分类
.NET Framework(4)
Avalon(18)
Miscellaneous(6)
News & Politics(2)
Patterns & Practices(1)
Personal Life(1)
Regular Expessions(5)
Reinvent The Wheels(1)
See Sharp(4)
Web Development(1)
Windows Forms(1)
随笔档案
2006年10月 (1)
2006年9月 (2)
2006年8月 (3)
2006年5月 (1)
2006年4月 (5)
2006年3月 (3)
2006年2月 (12)
2006年1月 (7)
2005年10月 (1)
2005年8月 (1)
2005年7月 (7)
2005年4月 (1)
Useful Links
A Guided Tour of Windows Presentation Foundation
Channel9
Keyboard Handling In Windows Forms