C# drawing on custom controls
<p>so I've created a custom control and I wanted to draw on that control
now the problem is that I can't use OnPaint event because I want to
draw at different times with different conditions.</p>

<p>here is the custom control function to draw a rectangle </p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>public void DrawARectangle(int x,int y,int height,int width)
{
    Graphics g = this.CreateGraphics();
    g.DrawRectangle(Pens.Black, x, y, height, width);
    g.FillRectangle(Brushes.Black, x, y, height, width);
}</code></pre>
</div>
</div>
</p>

<p>and I basically call it from my form , but it doesn't draw anything even after using the update() method. </p>