C# Excessive Repainting of WebView2 Control after Applying NativeWinAPI Styles

Having experiences various forms of flickering and graphical glitches, I searched online for possible solution. The only thing that worked straight away was accepted solution using NativeWinAPI from post just below: Avoid Flickering in Windows Forms?

Inserting this code in the main form of the application and keeping handle for 'this' practically eliminated every issue I had with graphics.

At least until I included a web browser (WebView2 Control). This control along side with the code from the post causes the control itself to constantly repaint itself. This in turn causes graphical issues within entire User Control that is parent to the WebView2. Other controls flicker in and out, which is super annoying and unpleasant.

Having spent hours(days really) trying to figure out what is wrong and practically rewriting entire project, the issue was located and it disappears straight after disabling function that sets the window style.

I am fairly certain that WebView2 Control is the only control having issues as I created OnPaint functions that write to console every time that the control was repainted, and disabling webview2 stops other controls from being repainted, while when enabled I get 100's of repaints within few seconds.

The problem is that disabling those changes makes the application look even worse with all the flickering and graphical glitches that it was fixing before.

I do not understand what the code from the link exactly does, and it quite frankly it goes over my head so if anyone could help me figure out how to solve the issue I would really appreciate it.

Read more here: https://stackoverflow.com/questions/65713336/c-sharp-excessive-repainting-of-webview2-control-after-applying-nativewinapi-sty

Content Attribution

This content was originally published by iluzek at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: