3 Attachment(s)
Repaint and Invalidated Regions
Ahh! - you guys are gonna hate me!
Back to the UserControl on top of a UserControl, this time it’s about invalidated regions, when, how and where the system knows to redraw.
I have a static image on a UserControl hosted by another UC, all is well. However once the second UC sited on the first has a dynamic area, it’s not properly repainted when another window is dragged across it.
This is a difficult one to describe so I tried using some pictures.
Normal View:
Attachment 152567
Calculator being dragged over UserControl towards the Right:
Attachment 152569
Calculator being dragged over UserControl towards the Bottom:
Attachment 152571
You can see where the dynamically drawn orange circle was once covered by the Calculator program wasn’t redrawn properly as it was uncovered. This not only happens when a window is dragged across, but also when the UserControl is moved off the edge of the screen and brought back.
I haven’t a clue as to what’s going on, but that didn’t stop me from thinking I knew. If Windows was not aware of the existence of the Orange Circle, being created dynamically, then it wouldn’t know to redraw it. And this would only be compounded by being a layer down within a UserControl from within a UC.
With this thinking I figured that if I signaled the Second UserControl that the Primary UserControl was being repainted, I’d get a trickle down effect and the Orange Circle would get redrawn. In the first UC paint event, I made a call to force the Second UC to repaint as well.
Too my utter shock and amazement, the damn thing worked! Placing debug statements everywhere, I could track one UC signaling the next to repaint. I knew something was still wrong simply because I’m just not that lucky!
Once compiled, the fix no longer worked!
It’s like the IDE works extra hard to ensure EXE compatibility by supplying more then the needed paint events to guarantee all runs properly while testing – heck I don’t know.
I setup DebugView so that I could debug my program while compiled, and sure enough the trickle down paint events were still called when running as an EXE, but the Orange Circle just doesn’t want to repaint.
It’s like VB is teasing me, letting me get so close to a finished project, then throwing me another curve!
Any ideas? Thanks.
Re: Repaint and Invalidated Regions
I've had a problem similar to this in one of my programs - NOT UC and never resolved. I Paint everything directly in a picturebox and do NOT use double buffering.
As I understand it, Windows OS tracks what needs to be rePainted, and then RePaints as resources are available. If I recall correctly (been quite a while while I played with it), even a direct call to Paint will NOT override what the OS wants to do. Believe API UpdateWindow rather than InvalidateRect may work.
Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function InvalidateRect Lib "user32" (ByVal hWnd As Long, lpRect As Long, ByVal bErase As Long) As Long
Private Declare Function UpdateWindow Lib "user32" (ByVal hWnd As Long) As Long
Re: Repaint and Invalidated Regions
Won't make assumptions about what events your drawing occurs in. If you get a UserControl_Paint event in your control only handle drawing in that event.
You mentioned a trickle down effect. It is actually a trickle up process. With windowless windowless controls, the container's hDC is being drawn on, so it gets the initial paint event. Then based on the area to be painted, it processes controls that intersect with that area, from lowest ZOrder to highest. Container passes the controls its hDC, clipped to the exclude all but the relative dirty area. After painting, then that result is passed to the next control, adjusting the clipping, and so on. That is the process, more or less. If the dirty area intersects a lower control that is covered by an opaque control, then that lower control won't be included in the paint chain -- not visible so why paint. Control transparency also influences which controls get included in the chain and which do not.
Re: Repaint and Invalidated Regions
Stuck
Sorry, I don't know jack about UC's, but I can make this observation ...
Green, blue, and pinkish-red are being "redrawn"
Is there any way to "reset" orange circle to be like the above when the calculator control is initialized?
Spoo
Re: Repaint and Invalidated Regions