久久久久久久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++)
主站蜘蛛池模板: 亚洲午夜精品视频 | 免费网站国产 | 日韩视频在线一区 | 日日爱夜夜操 | 欧美在线观看一区 | av免费入口 | 亚洲二区视频 | 又爽又黄axxx片免费观看 | 久草在线| 狠狠干影院 | 男女视频在线观看 | 国产成人精品一区二区三区网站观看 | 国产日韩欧美一区 | 日韩欧美精品一区 | 亚洲欧美一区二区三区在线 | 成人精品国产 | 国产三区在线观看视频 | 97超碰人人 | 欧美日韩国产三级 | 日韩精品免费在线观看 | 精品一区二区在线观看 | 欧美精品在线视频 | 97成人精品 | 亚洲免费精品 | 亚洲国产精品人人爽夜夜爽 | 福利片在线看 | 国产精品久久久av | 91视频在线看 | 黄色免费观看 | 最新伦理片 | 中文字幕一区二区三区在线观看 | 99久久免费精品国产男女高不卡 | 午夜免费观看网站 | 伊人一二三 | 成人一区二区三区在线观看 | 亚洲交性| 精品欧美视频 | 国产精品久久久久久久久久三级 | 国产精品夜夜春夜夜爽久久电影 | 国产亚韩 | 亚洲一区二区三区免费观看 |