学无先后,达者为师

网站首页 编程语言 正文

C#中将dateTimePicker初始值设置为空_C#教程

作者:唄小白   更新时间: 2023-04-07 编程语言

本文主要介绍了C#中将dateTimePicker初始值设置为空,具体如下:

C#中将dateTimePicker初始值设置为空

    //窗体初始化事件
    private void Form1_Load(object sender, EventArgs e)
    {
        this.dateTimePicker1.Format = DateTimePickerFormat.Custom;
        this.dateTimePicker1.CustomFormat = " ";  //" "引号中间必须有空格
        //this.dateTimePicker1.Checked = false;
    }

    private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
    {
        this.dateTimePicker1.Format = DateTimePickerFormat.Long;
        this.dateTimePicker1.CustomFormat = null;
    }

    //清空按钮事件
    private void button1_Click(object sender, EventArgs e)
    {
        this.dateTimePicker1.Format = DateTimePickerFormat.Custom;
        this.dateTimePicker1.CustomFormat = " ";
        this.dateTimePicker1.Checked = false;
    }

    //读取按钮事件
    private void button2_Click(object sender, EventArgs e)
    {
        if(dateTimePicker1.Text==" ")
        {
            this.textBox1.Text = "日期为空!";
        }
        else
        {
            this.textBox1.Text = this.dateTimePicker1.Text;
        }
    }

原文链接:https://blog.csdn.net/qq_43335448/article/details/127053797

相关推荐

栏目分类
最近更新