为Windows窗体C#设置日期时间选择器的最短日期

时间:2015-04-25 23:23:45

标签: c# winforms datetimepicker windows-forms-designer

我目前正在使用C#中的待办事项列表Windows窗体应用程序,它具有日期时间选择器,通过一些研究我能够找到我能够设置日期时间选择器的MinValue属性在表单的Designer选项卡中。

计划是通过以下代码设置日期时间选择器的最小日期值:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("cell") as! UITableViewCell
    for subView in cell.subviews {  
        if subView as? NSObject != cell.imageView {
            subView.removeFromSuperview()
        }
    }
    var statusImage = UIImage(named:imageConfigration(indexPath.row))!
    cell.imageView?.image = statusImage
    // ...
}

这不是问题,这段代码很好而且有效。它成功地将日期时间选择器的最小值设置为今天,从而基本上阻止用户在此日期之前选择日期。

但是,我的问题是,由于某种原因,Designer Tab决定重置它并自动删除此代码。

我只是想知道是否有办法阻止Designer Tab更改日期时间选择器的最小值?

1 个答案:

答案 0 :(得分:6)

您是否正在修改.Designer.cs文件?它会自动生成,您的所有更改都将丢失。您不应该手动编辑它。

在调用InitializeComponent()后立即将这些行移动到表单构造函数中以获得相同的效果。