简体   繁体   中英

User Control Refresh in Windows Form

I have a picture box. This picturebox is used for map.

Map has elemenst on it. For example, a display.

I created "display" from windows user control. This user control has "a panel, 3 pictureboxes on the panel".

Any user creates "displays" on the screen and save it as a control of a picturebox (map). When any user save the data, it is saved to the database.

In every second, I look at the picturebox (map), control the data on it and also database. If "display" changed its status(like shows go or stop, kind of traffic signs), then I found the changed ones and refresh it.

Now is the question: If I remove the display(user control) than add it again to map's (picturebox) controls, it works well. Updated "display" is seen on the map. However, any user can see the process because the display is disapeared for miliseconds and come back like flickering.

How can I refresh this user control without remove and add again process, Is there a method to refresh it some way?

To suppress any flickering, you can cheat by telling windows to suspend the parent control painting before your flicker generating operation, and resume it afterwards. Check this SO question out.

I do it quite often on my custom controls and it works great. You can even add the "SuspendDrawing" and "ResumeDrawing" static methods from the first answer as extension methods for Control class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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