Createparams is pretty cool!

Source: Internet
Author: User
Tags win32 window
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 :)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.