How to fix canvas flicker in Windows 7/8/10?

Use the paint event instead of backdrop.

Fixed Project

You beat me to it Neil :slight_smile:

Subclass the control to make it generic, but that should work nicely if no controls are overlapping.

You also only really need to perform the metal20 paint on the mouse leave as its the only one with a smaller image area. If both the images were the same size (with no glow) then you wouldn’t even need to do the erase with metal20, you could just overwrite.

There is probably a bug somewhere in Canvas.Background that is causing that flicker, it might be worth putting that project in as a ticket and see if its looked into.

[quote=343903:@Neil Burkholder]Use the paint event instead of backdrop.
Fixed Project[/quote]

Perfect! Thanks a lot. The Paint thing I never knew, and it makes sense now.

I would have done a subclass in my posted fix but I was afraid you would beat me. :wink:

Here’s a funny anecdote: Years ago I actually wrote animation code in RealBasic that was so bad it actually caused severe flicker on Mac.

The Windows flickering with Xojo apps give them an amateurish look.

Why after more than a decade, refuses Xojo inc to solve this very important problem (because the end user sees it)?

Their own IDE does not flicker and they claim it is made with Xojo.

Anyway, to all those people posted their solutions here I would say “Very well done, nice job!” (I mean it). Thank you very much for sharing which is very much appreciated.

Chris

[quote=344051:@Chris Verberne]The Windows flickering with Xojo apps give them an amateurish look.

Why after more than a decade, refuses Xojo inc to solve this very important problem (because the end user sees it)?

Their own IDE does not flicker and they claim it is made with Xojo.

Anyway, to all those people posted their solutions here I would say “Very well done, nice job!” (I mean it). Thank you very much for sharing which is very much appreciated.

Chris[/quote]
The problem isn’t with Xojo or RealBasic, it’s a Windows problem. Blame MS for not implementing Double Buffering in their OS like Apple has done with Mac OS X. I’ve played quite a few Windows games that had noticeable flicker in the graphics that were made with C++, C, or C#. When it comes to Windows it’s up to the program developer to do their own Double Buffering in their code.

I myself know the pains of implementing a good Double Buffer as I mainly program using Mac OS X.

Problem often enough is that an app developed on Mac will not show any trouble, because of double buffering built into Mac.

Then on Windows, the app is simply not built properly to minimize flicker on a non double buffered system. Xojo cannot anything about that. The only way is for the developer to refactor the app. Some prefer to blame rather than to work…

Because it’s easier… Now get back to work :stuck_out_tongue:

@Michel Bujardet, if you think I am lazy you are wrong. Many days, even weekends I work more than 16 hours a day. You are a great developer but sometimes you are too hasty by judging other people.

I do not blame, I am only frustrated because I could not find any solution myself for the flickering even when using single canvasses. Years ago, I came close with Eugene Dakins book about “Canvasses” but not close enough. Maybe I gave up too soon on the flickering problem but I could not get it right.

I will try out the solutions posted here to see if they work out for me. They look very promising and as said before, I highly appreciate the efforts of the members who contributed and shared those solutions.

If this works, my Xojo applications will benefit greatly from those solutions. I will mention those members in the “About” dialog of applications where I use their solutions.

Chris

I can tell you for sure that it is. I’ve worked on it. :wink:

But it does flicker and I know 100% that its written in Xojo because I see the same nvidia share bug where there is a graphics pause displaying the splash screen when it first loads. :slight_smile:

The Canvas book was my attempt to work with Xojo graphics to help increase awareness that quicker drawing can be performed in Xojo - which was over 3 years ago (time passes fast). The next graphical book was on OpenGL which has increased performance and less flickering in Windows, and its too bad that Mac is abandoning OpenGL for Metal because this would be a nice graphical option that is cross platform. I am currently writing a book on MemoryBlocks which will likely provide additional options for increased graphical speed.

Once the MemoryBlocks book is complete, then I should strongly consider updating the Canvas book, as there are many ways to increase graphics drawing performance on Windows (and the other OS’s).

My personal ultimate goal is to write a book on virtual reality graphics with Xojo, and it is slowly coming along and will not be ready for quite a number of years. In the meantime, maybe it will benefit the community for me to update the canvas book?

There are many great topics to write about with Xojo, and too little time to write it all :slight_smile:

Note that he mixed something up in the book: he used REFRESH when he should have used INVALIDATE, and vice versa.

INVALIDATE means “refresh at the next opportunity”.

REFRESH means “refresh NOW” which when used instead of invalidate causes additional redraws and therefore flicker.

I can say the problem with my little sample was fixed with the new version Neil sent me. My button no longer flickers at all and changes smoothly to another graphic, even when I mouse over it quickly.

[quote=344072:@Chris Verberne]@Michel Bujardet, if you think I am lazy you are wrong. Many days, even weekends I work more than 16 hours a day. You are a great developer but sometimes you are too hasty by judging other people.
[/quote]

You can work quite a bit and yet be in error. I am not ashamed to be a workaholic with no life when it comes to programming. Yet, sometimes, I embark on projects with the wrong method, and the result is not what I expect.

The principles of alleviating flicker have been repeated time and again. Proof that flicker free (or 99% or so) on Windows is possible in Xojo is the Windows IDE. As complex as it is, it is stable.

Sorry you take personally what I stated as a general fact. For better or worse, Xojo has IMHO much too touted cross platform as a simple process. People think that it is enough to take an app created on Mac, compile for Windows and get a working Windows application. It simply does not work like that. It still requires quite a bit of refactoring to be flicker free. Like it or not, it is a fact. Programming is not a matter of touchy feelings. It is hard logic.

I’m new here but have been working with Xojo for about 4 months as a trial user. I think part of the problem is everything you say is the opposite of what Xojo state. To quote their homepage:

Right next to that quote, a animation showing fields being dragged into place (i.e. no canvases etc)

So it is perfectly acceptable for someone (myself included), to expect Xojo to produce a Windows build that doesn’t produce flicker to a level that makes the end product look unprofessional. People are coding once (albeit on Mac) and expecting it to work on Windows. That is the problem - sure there may be a number of hackish ways to get Windows to work without flicker or minimal flicker. But that completely defeats the point of Xojo for me personally. The IDE is great IMO - drag fields into place, add the code and hit run. It’s simplistic and easy to build an app quickly. But for Windows you can’t do this - you have to delve into canvases and walk a very thin tight rope of what you can and cannot do UI wise.

If Xojo wasn’t advertised in the way it is then maybe that would be fair enough. But from the point of view of “Code once then deploy on macOS, Windows…” - it simply isn’t true - otherwise this thread and many like it on flickering wouldn’t exist. Xojo can blame Windows and the lack of double buffering within Win32 as much as they want. Sure it’s a oversight from Microsoft’s point of view. But from my perspective (i.e. the customer who won’t be buying a license after trailing your software) - my project will have to be in another language other than Xojo. From another coding language/company who have implemented double buffering/.Net. Sadly for me I will be moving on, I enjoy using Xojo and the language, but “Code once then delpoy…” simply isn’t true.

Stop ignoring the issue Xojo and find a solution - it doesn’t matter if every other Win32 app out there flickers - as a potential customer I don’t care and I’m sure others won’t either. I’ll hold hope for Xojo 2017r2, but I have a feeling my hopes will be dashed. Unfortunately Xojo seems intent on burying their head in the sand and ignoring it (there are threads going back years, I’m sorry, but you are ignoring it/customers). It is a shame because otherwise you have a solid product - something that could be quite special.

But precisely lays the lie. The big fat lie that you can develop on Mac, and magically flip a switch to obtain a perfectly well behaved Windows application. It simply is not true. Developing for Win32 requires precautions such as never stacking controls, et not paint in the window to start with.

I believe if Xojo was a little less cute with marketing, and a little more straightforward about the real specificities of Win32, there would be a lot less disappointed users blaming Windows, when in fact their code is not optimized for that platform.

In fact, Mac is so well optimized, and Xojo is so Mac oriented, the experience on a Mac is so smooth, it gives the false impression that it will be just as nice on Windows and Linux. Unfortunately, that is not at all the case, because both these platforms require extra precautions to get a smooth result.

On Windows, there is a framework that is virtually flicker-free : .Net. It has been the recommended framework for Windows development since 2002. That framework has been implemented in Visual Studio way back when, pretty much when Cocoa came to be for Mac. But is it that Xojo is culturally biased towards Mac, Cocoa was implemented in Xojo, but Windows was left with an archeological framework. Any time someone mentions .Net, it seems to fall in def ears. Yet, the Windows current state of the art has been .Net for quite some time, now.

Today, Windows uses a new API for the UWP apps (based on .Net), but it seems just as ignored. Truth is, Xojo is less and less a credible development platform for Windows. Sure, to occasionally generate a Windows executable maybe, but IMHO anybody truly interested in Windows cannot seriously consider Xojo as an up to date development tool.

[quote=344191:@Michel Bujardet]The principles of alleviating flicker have been repeated time and again. Proof that flicker free (or 99% or so) on Windows is possible in Xojo is the Windows IDE. As complex as it is, it is stable.
[…]
Programming is not a matter of touchy feelings. It is hard logic.[/quote]
Maybe writing a tutorial would be more useful than telling people off all the time?

Just an idea …

Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.