有关“针对每个人"的帮助环形 [英] Help about "For Each" Loop

查看:77
本文介绍了有关“针对每个人"的帮助环形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友

我在Vb.Net项目的表单上有大约十个DateTimePicker控件.

我想通过使用"For Each"循环将其默认值设置为当前日期.

Dear Friends

I have about Ten DateTimePicker controls on a Form in Vb.Net Project.

I want to set their default value the current date by using "For Each" loop.

Plz Guide Me how can I do that.

推荐答案

For each Con as Control In Me.Controls
If TypeOf Con Is DateTimePicker Then
DirectCast(Con,DateTimePicker).Value  = Now
End If
Next


您唯一的选择是对每个循环使用a在整个控件集合上,并使用控件名称或尝试进行的强制转换来确定哪些是datetimepicker控件.除非您花时间先创建控件集合,否则仅在此任务上这样做是多余的.
Your only option is to use a for each loop on the entire controls collection and use the control names or an attempted cast to work out which ones are datetimepicker controls. Unless you take the time to create a collection of controls first, which is redundant if you only do it for this task.


错误的方法选择.

为什么不在加载表单时将它们设置为今天"?
Bad choice of method.

Why not just set them at Today when the form loads?


这篇关于有关“针对每个人"的帮助环形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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