There is a piece of code:

protected override void OnPaint(PaintEventArgs e) { int n = 5; // число вершин double R1 = 25, R2 = 50; // радиусы double alpha = 30; // поворот double x0 = 60, y0 = 60; // центр PointF[] points = new PointF[2 * n + 1]; double a = alpha, da = Math.PI / n, l; for (int k = 0; k < 2 * n + 1; k++) { l = k % 2 == 0 ? R2 : R1; points[k] = new PointF((float)(x0 + l * Math.Cos(a)), (float)(y0 + l * Math.Sin(a))); a += da; } e.Graphics.DrawLines(Pens.Black, points); } 

What needs to be done, what would it be done by pressing a button on the form?

    1 answer 1

    assign an event to the button, the easiest way is to click 2 times on the button in the visual form editor if you are working with WinForm. Next, transfer the code to the method that is triggered by a button click.

    • So already tried. If you just move the text, the compiler swears that OnPaint(PaintEventArgs e) needed, and in the button - button_build_Click(object sender, EventArgs e) - Dmitriy
    • Use buttons in the event: using (var g = Graphics.FromImage (pictureBox1.Image)) {g.Graphics.DrawLines (Pens.Black, points); } - Sergey Neykovich
    • Did I do something wrong? goo.gl/onUcfw + goo.gl/tKKQ5E - Dmitriy
    • I apologize, I made a little mistake. You need to write: g.DrawLine (); - Sergey Neykovich Nov.
    • one
      Still, he doesn’t like something :( goo.gl/uF4o5p - Dmitriy