winform程序里想加一个像操作系统中时间设置的这种类似NumericUpDown控件的东东
想问下大家我怎么去重写NumericUpDown这个控件?或者可不可以加个TextBox再加两个Button这样去弄,可操作系统中的像“:”固定了不能动又是怎么做的?是不是加了几个TextBox又加了几个Label,反正就是想知道到底如何做就能做出这种效果?谢谢大家了!

解决方案 »

  1.   

    TextBox换成MaskedTextBox
    设置Mask属性为:“90:00”
    设置PromptChar属性为空格
      

  2.   

    派生NumericUpDown,重写N个方法
      

  3.   

    按照一楼说的试了一下,效果不是很好,也不知道如何去重写NumericUpDown.
      

  4.   

    VS自带的DateTimePicker这个控件就完全能够实现你所要的.
    将ShowUpDown 属性改成True
    将Format属性改成Custom
    将CustomFormat的属性改一下:
    CustomFormat="yyyy-MM-dd"  // 年月日
    CustomFormat="yyyy-MM-dd hh:mm:ss" // 年月日时分秒
    CustomFormat="hh:mm:ss" // 时分秒
    CustomFormat="'PM' hh:mm:ss" // PM标志 时分秒
    CustomFormat="'PM' yyyy-MM-dd hh:mm:ss" // 年月日时分秒可以在事件ValueChanged中根据Value的值来改PM或TMprivate void dateTimePicker1_ValueChanged(object sender, EventArgs e)
    {
                if (dateTimePicker1.Value.Hour > 6)
                {
                    dateTimePicker1.CustomFormat = "'PM' yyyy-MM-dd hh:mm:ss";
                }
                else
                {
                    dateTimePicker1.CustomFormat = "'TM' yyyy-MM-dd hh:mm:ss";
                }
    }
      

  5.   

    这方法果然好用,不然我肯定去重写numericupdown去了,谢谢5楼!!!