简体   繁体   English

C#主窗体使用动态控件刷新

[英]C# Main form refresh with dynamic controls

I'm developing a windows form application with controls on the main form that retreive their values from a mySQL database. 我正在开发一个Windows窗体应用程序,其主窗体上的控件可从mySQL数据库检索其值。 When the database gets updated I need the form to repaint and refresh the controls. 当数据库更新时,我需要表格来重新绘制和刷新控件。 Can anyone reccommend a solution to this? 任何人都可以推荐解决方案吗? On sub forms I've instantiated a new instance of the form and dispose of the old one, but I can't do that with the main form. 在子表单上,我实例化了表单的新实例并处理了旧的实例,但是我不能在主表单上做到这一点。 Thank-You for considering my question. 谢谢您考虑我的问题。

I'm not sure if correctly understood your question, but you could put your controls inside of a user control and use-it in the main form. 我不确定是否正确理解了您的问题,但是您可以将您的控件放在用户控件中,并以主要形式使用它。 Then, you could do the same you did with the forms: dispose and create a new one. 然后,您可以执行与表单相同的操作:处置并创建一个新表单。

This should solve your problem, however, you may have some problems with scrollbars and the resizing of your form. 这应该可以解决您的问题,但是,滚动条和表单的大小可能会有些问题。

If it were me, I wouldn't dispose of a UI with another, that is in focus for the user. 如果是我,我不会与另一个UI一起丢弃,这是用户关注的重点。 That would kind of irritate the user especially if the update is automatic. 这会激怒用户,特别是如果更新是自动的。

Suppose you have view-only controls like gridview or labels updating with live values, then you can put a time interval and display a seconds ticker clearly telling the user when an update is going to happen. 假设您具有仅查看控件,例如gridview或使用实时值更新的标签,那么您可以放置​​一个时间间隔并显示秒数指示器,以清楚地告诉用户何时进行更新。

You should consider having an update method on all your controls (or one usercontrol having all the controls) which you can trigger to update the controls at timed intervals. 您应该考虑对所有控件(或一个具有所有控件的用户控件)使用一种更新方法,您可以触发该更新方法以定期更新这些控件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM