I'm developing a windows form application with controls on the main form that retreive their values from a mySQL database. When the database gets updat开发者_运维技巧ed 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. 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.
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.
精彩评论