Question

I"m making a custom control that draws my simulation. The problem is, that when constantly invalidating it (which is needed because each tick the appeareance is changed) it blocks other controls from being drawn (for example the property grid is not updating as long as I'm dragging an object in the simulation with my mouse).

How can i prevent this behaviour? How does the drawing of windows forms work? Also when having two instances of this control on the form the first one blocks the second one. So only one gets drawn and the other just stays blank.

Anyone here who already made complex user controls? I cant use other rendering mechanisms, because the program is supposed to be used in office environments which might not have a suitable graphics card for hardware accelerated drawing.

//edit:found the problem. I had an Invalidate() in my drawcall in a submethod facepalm

Was it helpful?

Solution

Okay, dirty workaround incoming:

i used a forms timer to constantly redraw my stuff. that keeps the gui from locking up. its ugly...

OTHER TIPS

I know I'm late to the party, but you may want to look at the Form.OnIdle event.

This event occurs when your app's message queue goes empty, which implies that all other UI updating and user-event handling is done (for the moment). Unless you've got something that's generating a constant stream of messages all the time, they tend to come in bursts during UI interaction. The end of a burst is a pretty good time to update your custom control.

The timer isn't a messy hack at all, IMO. It's a good way to establish a minimum update frequency. Typically, updates are only necessary when the information being displayed changes, or a window covers and then uncovers yours, forcing a redraw. But if you're not tracking changes that way, or the underlying information is changing hundreds of times per second, a timer is a good way to throttle your updates so that they only happen within a certain frequency range.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top