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

            
        }

    }


  • 相关阅读:
    网络科学导论【第二章】读书脑图
    稳定匹配
    Machine learning(3-Linear Algebra Review )
    Machine learning(2-Linear regression with one variable )
    Machine learning(1-Introduction)
    1710. Maximum Units on a Truck (E)
    0729. My Calendar I (M)
    0105. Construct Binary Tree from Preorder and Inorder Traversal (M)
    0746. Min Cost Climbing Stairs (E)
    0128. Longest Consecutive Sequence (M)
  • 原文地址:https://www.cnblogs.com/tonyepaper/p/1180107.html
Copyright © 2011-2022 走看看