title: VCL custom TGraphicControl messes up only on a remote desktop
body: <p>In a C++ application (using C++Builder 10.3 and VCL), I use a custom class derived from <code>TGraphicControl</code> to draw a custom user interface and a small plot of changing data.</p>
  
  <p>Everything works well in Windows 10 and Windows 7, but if I execute the application in a Remote Desktop session (via a native Windows service) with each redraw the graphics are messed up more. </p>
  
  <p>The problem starts with disappearing elements and wrong <code>LineTo</code> endpoints, but sometimes the elements appear even in a different dialog instead. </p>
  
  <p>Also, switching on a PC from direct to remote access causes dynamically inserted VCL <code>TComboBox</code> elements to get invalid parents and owners, followed by an error message that the <code>TComboBox</code> class is unknown.</p>
  
  <p>I'm using <code>ClientRect</code> in my code. Is this perhaps the problem when working in remote sessions?</p>
  
  <p>Code where I see the problem (it's a bit long and I have trouble making a minimal example without omitting possible causes of the problem)<br>
  cpp: <a href="https://pastebin.com/vpk3De7J" rel="nofollow noreferrer">https://pastebin.com/vpk3De7J</a> (painter at line 228)<br>
  header: <a href="https://pastebin.com/3pLy4dEY" rel="nofollow noreferrer">https://pastebin.com/3pLy4dEY</a></p>
  
  <pre class="lang-cpp prettyprint-override"><code>class CustomTrgDrawings : public TGraphicControl
  {
  private:
      void __fastcall Paint(void);
  public:
      __fastcall CustomTrgDrawings(TComponent* Owner);
      bool updating;      //stops painting when true
  }; 
  
  __fastcall CustomTrgDrawings::CustomTrgDrawings(TComponent* Owner)
      : TGraphicControl(Owner)
  {
      updating = true;
  }
  
  void __fastcall CustomTrgDrawings::Paint(void)
  {
      if (!updating)
          return;
  
      Canvas-&gt;Brush-&gt;Color = TColor(0x220022);
      Canvas-&gt;Brush-&gt;Style = bsSolid;
      Canvas-&gt;Pen-&gt;Color = TColor(0x222222);
      Canvas-&gt;Pen-&gt;Style = psSolid;
      Canvas-&gt;Pen-&gt;Width = 1;
  
      Canvas-&gt;FillRect(ClientRect);
  }
  
  //---insertion in a vcl form
  void __fastcall TMyForm::FormCreate(TObject *Sender)
  {
      //uses TLabel *myLabel as container
      CustomTrgDrawings *drg = new CustomTrgDrawings(myLabel);
  }
  </code></pre>