form中有两个日期一个是记录日期,另一个是交款日期
当没有交款时,记录日期需要为空白
两个日期使用DATE TIME PICKER
请问如何另此控件空

解决方案 »

  1.   

     System.Windows.Forms.DateTimePicker dtp;
                    dtp.ShowCheckBox = true;
                    dtp.Checked = false;
      

  2.   

    checkbox没选中时是不保存数据的
      

  3.   

    MessageBox.Show(this.dtpdate.Value.ToString(),"test");
    无论是否被选中,都show出日期
      

  4.   

    不管怎样,它的TEXT属性不可能为空,它的值与一个MONTH CALENDAR绑定了。要设置记录日期为空,可以在保存数据是设置为空就行。如果非要实现为空的效果,可以用一个TEXTBOX,它的KEYPRESS事件中e.handled=true即保证不让用户手动输入
    private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
            {
                e.Handled = true;
            }        private void textBox1_MouseClick(object sender, MouseEventArgs e)
            {
                if (this.dateTimePicker1.Visible == false)
                {
                    this.dateTimePicker1.Visible = true;
                }
            }        private void textBox1_MouseDown(object sender, MouseEventArgs e)
            {
                if (this.dateTimePicker1.Visible == false)
                {
                    this.dateTimePicker1.Visible = true;
                }
            }        private void textBox1_MouseEnter(object sender, EventArgs e)
            {
                if (this.dateTimePicker1.Visible == false)
                {
                    this.dateTimePicker1.Visible = true;
                }
            } 
            //控制让其隐藏
            private void dateTimePicker1_MouseLeave(object sender, EventArgs e)
            {
                if (this.dateTimePicker1.Visible == true)
                {
                    this.dateTimePicker1.Visible = false;
                }
            }
            //赋值
            private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
            {
                this.textBox1.Text = this.dateTimePicker1.Text;
            }
    当然还有其他的方法了,不赘述
      

  5.   

    這個方法確實能解實現,但是.NET是否沒有直接解決辦法呢?
      

  6.   

    下边的代码可以实现你要的功能,让dateTimePicker1控件显示为空,下边代码的意思就是:让控件使用自定义的格式显示。 dateTimePicker1.Format = DateTimePickerFormat.Custom;
    dateTimePicker1.CustomFormat = "  ";希望对你有用!
      

  7.   

    MessageBox.show(dateTimePicker1.Value,"test")
    是有数据显示的
      

  8.   

    变相的实现一下,不需要显示的时候隐藏dtp,放一个空的文本框在上面好了。
      

  9.   

    需要另外的一个控件来控制是否保存,
    再说了,可以从业务上处理啊,没有较宽日期的就那个日期添加null或者不添加啊