Probably I 've been in the WPF World for so long that I need to try something different, yesterday, I come into ss 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
{
Get
{
Createparams parameters = base. createparams;
Parameters. classstyle | = cs_dropshadow;
Return parameters;
}
}
}
Public class numberbox: textbox
{
Private Static int32 es_number = 0x2000;
Protected override 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 secret T 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 :)