惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Docker
B
Blog RSS Feed
Microsoft Security Blog
Microsoft Security Blog
Y
Y Combinator Blog
N
Netflix TechBlog - Medium
M
MIT News - Artificial intelligence
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
B
Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
C
Check Point Blog
The GitHub Blog
The GitHub Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
P
Proofpoint News Feed
Martin Fowler
Martin Fowler
大猫的无限游戏
大猫的无限游戏
GbyAI
GbyAI
博客园_首页
A
About on SuperTechFans
Blog — PlanetScale
Blog — PlanetScale
人人都是产品经理
人人都是产品经理
T
Tailwind CSS Blog
aimingoo的专栏
aimingoo的专栏
T
The Blog of Author Tim Ferriss
The Cloudflare Blog

博客园 - Sheva

Two Xaml Tricks - Sheva I See Cool Stuff Today DataTemplate Is A Bit Naughtier To Play With XmlnsDefinitionAttribute Is Pretty Nifty Application.DoEvents In WPF 征召译者 C# Trivia Test In-Place Editing In WPF SingleLinkedList Implementation Data Binding In WPF C# Application Markup Language Regex 101 Exercise I10 - Extract repeating hex blocks from a string AvalonPaint: Features Added Regex 101 Exercise I9 - Count the number of matches Crossbow: Hosting WPF Controls In Winforms Application Crossbow? WTF? The Architecture Of Avalon Drop Shadow Effect In WPF XamlReader.Load(): Build Up Your Own XamlPad
CreateParams Is Pretty Cool!
Sheva · 2006-04-29 · via 博客园 - Sheva

Posted on 2006-04-29 23:30  Sheva  阅读(2526)  评论()    收藏  举报

    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:)