久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何更改 .NET DateTimePicker 控件以允許輸入空值?

How to alter a .NET DateTimePicker control to allow enter null values?(如何更改 .NET DateTimePicker 控件以允許輸入空值?)
本文介紹了如何更改 .NET DateTimePicker 控件以允許輸入空值?的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

更改 .NET DateTimePicker 控件以允許用戶輸入 null 值的最簡(jiǎn)單、最可靠的方法是什么?

What's the easiest and most robust way of altering the .NET DateTimePicker control, to allow users to enter null values?

推薦答案

這是 CodeProject 文章中關(guān)于創(chuàng)建 可以為空的 DateTimePicker.

Here's an approach from this CodeProject article on creating a Nullable DateTimePicker.

我已覆蓋 Value 屬性以接受 Null 值作為 DateTime.MinValue,同時(shí)保持 MinValue 的驗(yàn)證標(biāo)準(zhǔn)控件的code>和MaxValue.

I have overridden the Value property to accept Null value as DateTime.MinValue, while maintaining the validation of MinValue and MaxValue of the standard control.

這是文章中自定義類組件的一個(gè)版本

Here's a version of the custom class component from the article

public class NullableDateTimePicker : System.Windows.Forms.DateTimePicker
{
    private DateTimePickerFormat originalFormat = DateTimePickerFormat.Short;
    private string originalCustomFormat;
    private bool isNull;

    public new DateTime Value
    {
        get => isNull ? DateTime.MinValue : base.Value;
        set
        {
            // incoming value is set to min date
            if (value == DateTime.MinValue)
            {
                // if set to min and not previously null, preserve original formatting
                if (!isNull)
                {
                    originalFormat = this.Format;
                    originalCustomFormat = this.CustomFormat;
                    isNull = true;
                }

                this.Format = DateTimePickerFormat.Custom;
                this.CustomFormat = " ";
            }
            else // incoming value is real date
            {
                // if set to real date and previously null, restore original formatting
                if (isNull)
                {
                    this.Format = originalFormat;
                    this.CustomFormat = originalCustomFormat;
                    isNull = false;
                }

                base.Value = value;
            }
        }
    }

    protected override void OnCloseUp(EventArgs eventargs)
    {
        // on keyboard close, restore format
        if (Control.MouseButtons == MouseButtons.None)
        {
            if (isNull)
            {
                this.Format = originalFormat;
                this.CustomFormat = originalCustomFormat;
                isNull = false;
            }
        }
        base.OnCloseUp(eventargs);
    }

    protected override void OnKeyDown(KeyEventArgs e)
    {
        base.OnKeyDown(e);

        // on delete key press, set to min value (null)
        if (e.KeyCode == Keys.Delete)
        {
            this.Value = DateTime.MinValue;
        }
    }
}

這篇關(guān)于如何更改 .NET DateTimePicker 控件以允許輸入空值?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How to check if String is null(如何檢查字符串是否為空)
Equals(item, null) or item == null(Equals(item, null) 或 item == null)
Overriding == operator. How to compare to null?(覆蓋 == 運(yùn)算符.如何與空值進(jìn)行比較?)
What does the question mark in member access mean in C#?(成員訪問中的問號(hào)在 C# 中是什么意思?)
The || (or) Operator in Linq with C#(||(或)C# 中的 Linq 運(yùn)算符)
C# null coalescing operator equivalent for c++(C# 空合并運(yùn)算符等效于 C++)
主站蜘蛛池模板: 亚洲激情在线观看 | 黑人系列合集h | 免费一级黄色片 | 日韩黄色在线视频 | 91日韩欧美 | 免费一级黄色 | 一区二区三区视频在线播放 | 国产日批视频 | 亚洲天堂欧美 | 国产一区在线视频 | 一级片观看| 色多多视频在线观看 | 国产wwwwww| 欧美日韩综合网 | 91视频免费观看 | 一区二区三区不卡视频 | 亚洲综合第一页 | 日韩欧美小视频 | 91午夜理伦私人影院 | 久久精品久久久久 | 午夜爱| 日韩一级在线观看 | 成人福利视频在线观看 | 亚洲深夜福利 | 不卡在线视频 | 国产乱国产乱300精品 | 五月婷婷色 | 午夜88 | 国产视频一区二区在线播放 | 亚洲国产黄色 | 青青草免费在线视频 | 成人黄色小视频 | 91午夜精品亚洲一区二区三区 | 国产精品伦一区二区三级视频 | 国产精品手机在线观看 | 天天干夜夜 | 久久久久久国产精品 | 色一情一乱一伦一区二区三区 | 国产丝袜av | 欧美性猛交99久久久久99按摩 | 久草网在线观看 |