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

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

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

問題描述

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

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

推薦答案

這是 CodeProject 文章中關于創建 可以為空的 DateTimePicker.

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

我已覆蓋 Value 屬性以接受 Null 值作為 DateTime.MinValue,同時保持 MinValue 的驗證標準控件的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.

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

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;
        }
    }
}

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

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

相關文檔推薦

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?(覆蓋 == 運算符.如何與空值進行比較?)
What does the question mark in member access mean in C#?(成員訪問中的問號在 C# 中是什么意思?)
The || (or) Operator in Linq with C#(||(或)C# 中的 Linq 運算符)
C# null coalescing operator equivalent for c++(C# 空合并運算符等效于 C++)
主站蜘蛛池模板: 国产成人精品a视频一区www | 男女羞羞视频网站 | 亚洲一区在线播放 | 欧美中文字幕一区二区三区 | 久久久久久久一区 | 九九视频在线观看视频6 | 午夜免费影视 | 九九看片| 亚洲精品久久久久久久久久久久久 | 中文字幕专区 | 欧美日韩福利视频 | av黄在线观看 | 欧美日韩视频在线第一区 | 成人av电影在线 | 国产精品一区在线观看 | 天天操天天插 | 韩日精品一区 | 欧美色人| 久久毛片 | 精品亚洲一区二区三区四区五区高 | 正在播放亚洲 | 国产一区不卡 | 欧美理论 | 午夜在线 | 国产精品成av人在线视午夜片 | 中文字幕国产 | 午夜网址| 免费一级欧美在线观看视频 | 欧美乱码精品一区二区三区 | 久久一区二区免费视频 | 一区二区三区中文字幕 | 青青草综合 | 国产农村妇女毛片精品久久麻豆 | 日韩在线欧美 | 天天操夜夜操 | 在线观看国产精品一区二区 | 国产精品中文 | 日韩三极| 欧美在线观看一区 | 亚洲精品一区二区三区在线观看 | 紧缚调教一区二区三区视频 |