Prevent window refresh

On windows in my mousedown event I have some code to resize/move objects and list boxes around in a window. I was looking for ways to reduce flicker and happened to notice that refreshes are taking place multiple times during the event loop.

For example: I have a list box that I’m essentially resizing smaller from the top down. I first change the top position and then adjust the height. The listbox is actually drawn at its original height in a lowered position first (overlapping a control below it) and then drawn again at it’s adjusted height.

Is it possible to prevent refreshes until the loop is finished. I wish the window.paint event used a Boolean return to prevent painting. Then I could set a Dontrefresh flag in my mouse down loop.

Why would you be using a loop in mousedown ?

Sorry, wrong terminology. I meant mousedrag event. It loops/reoccurs continuously why I’m resizing my control. I would like to position all my controls in the event, and have the window only be redrawn once at the end of the event. I originally assumed this to be the case be see I was wrong.

The Resized event happens only once, at the end of a resize operation.
Perhaps that is what you want if you only want to do the resize/reposition once?

Thanks for the quick response. I’m not resizing the window. I’m only resizing/repositioning listboxes within a window.
I change the mouse pointer for the edge of my list box and then use the listbox.mousedrag event to accomplish the resizing.

See https://forum.xojo.com/6484-tip-removing-flicker-on-windows/14

I tried that and it helps but when the window is redrawn is first draws a white background and refreshes the whole window even using self.refresh false

Can I create a windows app that resizes like this using Xojo?

The above program makes me jealous since my app looks like this:

If you look closely, the window above does not resize the listbox, it simply pushes it to the right.

For your project, I would instead use a canvas overlaid on top of it with in the Paint event a simple drawRect() that shows the frame, and actually resize the canvas. Then when the mouse is released, I would resize the containerControl and make the canvas invisible.

Windows does that when live Resize is off.

use invalidate instead of refresh

I turn live resize off and didn’t notice any visible difference.

Sorry for my lack of comprehension. I’m not quite sure I follow you with the canvas solution. Can you give a few more details.

You put a canvas over the ContainerControl, same size, make it invisible.

In its paint event :
g.Drawrect(0,0,me.width, me.height)

When you click on the edge of the ContainerControl, make the canvas visible, and instead of resizing the CC, resize the canvas.

When you are finished resizing the canvas and release the mouse, make it invisible and resize the containerControl to the size of the canvas.

does the IDE flicker like crazy for you when you resize its left hand navigator & right hand inspector / library ?

those ARE just container controls that we invalidate & redraw as you resize them

Here are the results using invalidate:

[quote=302357:@Norman Palardy]does the IDE flicker like crazy for you when you resize its left hand navigator & right hand inspector / library ?

those ARE just container controls that we invalidate & redraw as you resize them
[/quote]
Good point. It’s not nearly as smooth as Source Tree, but it’s definitely acceptable.
Now I just need to figure out what I’m doing wrong.

@Neil Burkholder , have u tried rubber views (http://rubberviews.com/) to see if it “refreshes” less?

I’ve messed with it some. I’m beginning to think my problem is due in part to all the nesting: Window>TabControl>PagePanel>Rectangle>Listboxes and other controls…

I’m experimenting with taking a snapshot of the rectangle and scaling the ‘picture’ then showing the actual layout after the mouse is released.

Ok I’ve wasted enough of time on this. I think the problem is that I’m using a rectangle and placing my controls on the rectangle. This makes it easy to layout using the control locks to lock controls to the rectangle edges. I can then simply resize/reposition the rectangle. I believe the right way would have been to use a container class instead.

you can use a canvas instead of a rectangle

rectangles will try to draw a bunch where canvases only do if you put code in their paint event

Norman, You saved my night… or what’s left of it.

Using a canvas as the parent I drawing the controls into the canvas and bingo no more flicker, because instead of a white background when refreshing the controls image on the canvas is show.

Thank you much!

I just noticed that using the AllowRedraw (I disable the auto refresh when turning AllowRedraw back on), when I call Window.RefreshRect(x,x,x,x) the entire window is redrawn.