First off, that is C# code, not C++ - they are very different languages which share some common syntax. It is important that you tag questions correctly, or you will reduce the number of potential answerers significantly.
You can do it directly in a button click handler, but ... it's a bad idea. Why I say that is that such drawings aren't persistent: as soon as anything else requires your form to be redrawn your new changes will be discarded - and that includes you changing the size of your form, minimising it, maximising it, or even another app moving over it's surface.
To do that, you get a graphics context from the system, draw onto that, and then dispose of the context.
How to: Create Graphics Objects for Drawing - Windows Forms | Microsoft Docs[
^] shows you how.
What you should be doing is drawing in the Paint event handler, and forcing a repaint by Invalidating the control / form on which you want to draw:
Control.Invalidate Method (System.Windows.Forms) | Microsoft Docs[
^]