如何在不绘制控件的情况下更新DateTimePicker.text? [英] How to update DateTimePicker.text without drawing the control?

查看:93
本文介绍了如何在不绘制控件的情况下更新DateTimePicker.text?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

DateTimePicker似乎有一个非常不受欢迎的"功能"。在以编程方式绘制控件之前不更新Text值。这是我的方案。

DateTimePicker seems to have a very undesirable "feature" of not updating the Text value until the control is drawn programmatically. Here's my scenario.

我开发了一个调度程序,它使用DateTimePickers矩阵来表示一周中每一天的ON和OFF时间。我将这些值存储在XML文件中,以便程序可以在每次启动时加载存储的值。 XML值是每个调度程序触发器的DateTime的文本表示形式

I have developed a scheduler that uses a matrix of DateTimePickers to represent ON and OFF times for each day of the week. I store these values in an XML file so that the program can load the stored values each time it starts. The XML values are text representations of the DateTime for each scheduler trigger.

当我加载文件时,我将DateTimePicker.Text设置为等于存储的XML文本表示形式。 DateTime值。这正确设置了DateTimePikcer.Value,但DateTimePicker.Text在加载时未更新。事实上,如果我从不绘制DateTimePikcer
控件,那么"文本永远不会更新"。因此,下次保存XML文件时,DateTimePicker.Text为空!

When I load the file, I set the DateTimePicker.Text equal to the stored XML text representation of the DateTime value. This correctly sets the DateTimePikcer.Value, but the DateTimePicker.Text is NOT updated at load time. In fact, if I never draw the DateTimePikcer control, THE TEXT NEVER GETS UPDATED. So the next time I save the XML file, the DateTimePicker.Text is blank!

因为我不希望强制我的用户每次使用时始终查看(绘制)调度程序该程序,我需要一些方法来以编程方式更新此文本值。 

Since I don't want to force my users to always view (draw) the scheduler each time they use the program, I need some way to update this text value programmatically. 

是否有人熟悉此"功能"?有关如何在不绘制控件的情况下更新DateTimePicker.Text的任何建议吗?

Is anyone familiar with this "feature"? Any suggestions on how to update the DateTimePicker.Text without drawing the control?

Thx,MikeH

Thx, MikeH

推荐答案

嗨MikeH,

Hi MikeH,

>>当我加载文件时,我将DateTimePicker.Text设置为等于DateTime值的存储XML文本表示。

 

 

尝试设置  DateTimePicker.Value属性 ,然后设置 DateTimePicker。 无效 (),
DateTimeP icker。 更新()
DateTimePicker。 刷新() 进行刷新。

Try to set  DateTimePicker.Value property, and then setDateTimePicker.Invalidate(), DateTimePicker.Update() or DateTimePicker.Refresh() to refresh.

最Invalidate的时间是足够的,并且是可取的,因为您可以执行一堆失效(显式或隐式),然后让控件在应用程序空闲时自行重绘。当您希望控件
立即重新绘制时,建议使用"更新"或"刷新",因为应用程序在用户显着的时间段内不会处于空闲状态。

Most of the time Invalidate is sufficient, and advisable as you can do a bunch of invalidations (either explicit or implicit) and then let the control repaint itself when the app is idle. It is advisable to use Update or Refresh when you want the control to immediately repaint because the app will not be idle for a user-noticable period of time.

最好的问候,

Bob

Bob


这篇关于如何在不绘制控件的情况下更新DateTimePicker.text?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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