在Windows应用程序中使用csharp进行Datepicker验证 [英] Datepicker Validation using csharp in windows application

查看:96
本文介绍了在Windows应用程序中使用csharp进行Datepicker验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个日期选择器,一个有开始日期,另一个有结束日期。



开始日期datepicker1)结束日期(datepicker2)



当我点击datepicker1中的第7个星期一日期时,自动12月星期六显示在datepicker2中。



工作正常。



i有一个验证datepicker1怎么办。



在datepicker1中总是用户只选择星期一,如果用户选择任何其他日期将显示消息选择星期一。



如何在datepicker中的csharp中进行验证。

i have two date picker, one has start date and another one has End date.

Start date datepicker1) End date(datepicker2)

when i click the 7th Monday date in datepicker1 automatically 12th Saturday is displayed in the datepicker2.

that is working fine.

i have one validation datepicker1 how to do.

in the datepicker1 always user choose the day Monday only, if user choose any other day will display the message choose the Monday .

how to do that validation in csharp in datepicker.

推荐答案

我不认为我们可以在此控件中禁用一周中的某些天。但是我们可以强制用户将所选日期作为他选择任何日期的星期一的星期一。这可以这样做:



I dont think we can disable certain days of week in this control. But we can force the user to get the selected day as monday of the week from which he has selected any date. This can be done like this:

private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
       {
           DateTime dt = dateTimePicker1.Value;

           if (dt.DayOfWeek != DayOfWeek.Monday)
           {
               while (dt.DayOfWeek != DayOfWeek.Monday)
               {
                   dt = dt.AddDays(-1);
               }
           }

           dateTimePicker1.Value = dt;
       }



P.S。我不建议这样做,因为这是非常脏的方法。我建议你在更改时验证日期并让用户知道问题,以便他可以选择星期一。


P.S. i would not recommend doing this, as this is pretty dirty approach. I would suggest you validate the date when changed and let the user know the problem so that he can select a Monday.


这篇关于在Windows应用程序中使用csharp进行Datepicker验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆