如何在 VB.NET 中制作只读日期时间选择器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14376388/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I make a Readonly DateTime picker in VB.NET
提问by Thanzeem
Can anyone know how to make a read-only DateTime picker in VB.NET?
谁能知道如何在 VB.NET 中制作只读的 DateTime 选择器?
采纳答案by Steven Doggart
There is no built-in way to change the DateTimePickercontrol to read-only. You could probably create your own custom read-only control that either contains or inherits the DateTimePickercontrol, however, you have several other much simpler options:
没有将DateTimePicker控件更改为只读的内置方法。您可能可以创建自己的自定义只读控件来包含或继承该DateTimePicker控件,但是,您还有其他几个更简单的选项:
- If you never need the value to be editable, and it is only ever read-only, then don't use the
DateTimePickercontrol. You should, instead, use aLabelcontrol. - If it's sometimes editable and sometimes read-only, use the
DateTimePickercontrol and just toggle theEnabledproperty to switch it between editable and read-only modes. - If you want it to look like other entry controls, but not be grayed-out (as is the case when you disable it), then use a
TextBoxcontrol and set it'sReadOnlyproperty toTrue.
- 如果您从不需要该值是可编辑的,并且它只是只读的,则不要使用该
DateTimePicker控件。相反,您应该使用Label控件。 - 如果它有时是可编辑的,有时是只读的,请使用
DateTimePicker控件并切换该Enabled属性以在可编辑和只读模式之间切换。 - 如果您希望它看起来像其他条目控件,但不会变灰(就像禁用它时的情况),则使用
TextBox控件并将其ReadOnly属性设置为True.

