zoukankan      html  css  js  c++  java
  • 用于处理DBNull问题的DateTimePicker

    08/5/3改进版,请大家给些建议.谢谢!
    using System;
    using System.Collections.Generic;
    using System.Text;

    using System.Windows.Forms;
    using System.ComponentModel;
    using System.Text.RegularExpressions;

    namespace WinUI
    {
        
    /// <summary>
        
    /// 用于处理DBNull问题的DateTimePicker
        
    /// </summary>

        public class MDateTimePicker :DateTimePicker
        
    {
            
    public object Value
            
    {
                
    get
                
    {
                    
    return base.Value;
                }

                
    set
                
    {
                    
    try
                    
    {
                        DateTime dt
    =Convert.ToDateTime(value);
                        
    base.Value = dt;
                    }

                    
    catch (Exception ex)
                    
    {
                        
    base.Value = MaxDate;
    ;
                    }

                }

            }

            
    protected override void OnTextChanged(EventArgs e)
            
    {
                
    base.OnTextChanged(e);
                
    if (Convert.ToDateTime(Value) == MaxDate)
                
    {
                    Format 
    = DateTimePickerFormat.Custom;
                    CustomFormat 
    = " ";
                }

                
    else
                
    {
                    Format 
    = DateTimePickerFormat.Long;
                }

            }

            
    protected override void OnClick(EventArgs e)
            
    {
                
    base.OnClick(e);
                onEdit();
            }

            
    protected override void OnKeyDown(KeyEventArgs e)
            
    {
                
    base.OnKeyDown(e);
                
    if (e.KeyCode == Keys.Delete)
                
    {
                    
    this.Value = MaxDate;
                }

                
    else
                
    {
                    onEdit();
                }

            }

            
    private void onEdit()
            
    {
                Format 
    = DateTimePickerFormat.Long;
                Value 
    = DateTime.Now;
            }

            
        }

    }


  • 相关阅读:
    [jQuery]jQuery DataTables插件自定义Ajax分页实现
    [.NET Core].NET Core R2安装教程及Hello示例
    PHP openssl加密扩展使用总结
    PHP 运行方式(PHP SAPI介绍)
    SQL用法操作合集
    PHP mcrypt加密扩展使用总结
    PHP header函数的几大作用
    JS中的Navigator 对象
    数据在内存中存储的方式:大端模式与小端模式
    C++中各种数据类型占据字节长度
  • 原文地址:https://www.cnblogs.com/tonyepaper/p/1180107.html
Copyright © 2011-2022 走看看