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

            
        }

    }


  • 相关阅读:
    操作系统——理论知识
    BEGIN-4 Fibonacci数列
    BEGIN-3 圆的面积
    面向对象三大特征之一:多态
    面向对象三大特征之二:继承
    package---包
    面向对象三大特征之一:封装
    关键字:This(上)
    无参构造与有参构造
    面向对象
  • 原文地址:https://www.cnblogs.com/tonyepaper/p/1180107.html
Copyright © 2011-2022 走看看