title: C# Excessive Repainting of WebView2 Control after Applying NativeWinAPI Styles
body: <p>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:
  <a href="https://stackoverflow.com/questions/12813752/avoid-flickering-in-windows-forms">Avoid Flickering in Windows Forms?</a></p>
  <p>Inserting this code in the main form of the application and keeping handle for 'this' practically eliminated every issue I had with graphics.</p>
  <p>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.</p>
  <p>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.</p>
  <p>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.</p>
  <p>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.</p>
  <p>I do not understand what the code from the link exactly does (too advanced/complex for my current knowledge). If anyone could help me figure out how to solve the issue I would really appreciate it.</p>
  <p>Update:
  I created a small demo project for anyone interested in addressing this.
  It is a 7zip of the project placed on google drive:</p>
  <p><a href="https://drive.google.com/file/d/17z3BSirIb5digN-5vSi1Q8DwiR-b3pWv/view?usp=sharing" rel="nofollow noreferrer">FlickeringDemo.7z</a></p>
  <p>Microsoft Edge Canary Browser is required for WebView2 to work correctly:
  <a href="https://www.microsoftedgeinsider.com/en-us/download" rel="nofollow noreferrer">Download Edge Canary Here</a></p>
  <p>Main form has bool flag that control graphical improvements and flickering. Simply set it to true/false to observe the difference.</p>
  <p>Debug.WriteLine(); - will output Paint Event counter into console in Visual Studio.</p>
  <pre><code>bool FlickerEnabled = false;
  public MainForm()
  {
      InitializeComponent();
      if (FlickerEnabled)
      {
          InitialiseGraphicalFixes();
      }
  }
  </code></pre>