c# winforms proportional change of graphics scaling window

Viewed 21

when I press the button, I draw a koch snowflake.but please tell me how I can make the snowflake proportionally change size when I change the window scale?

private void button1_Click(object sender, EventArgs e)
{
    pen_white = new Pen(Color.White, 1);

    holst = CreateGraphics();
    holst.Clear(Color.CadetBlue);
    
    var point1 = new PointF(200, 200);
    var point2 = new PointF(500, 200); 
    var point3 = new PointF(350, 400);
    holst.DrawLine(pen_white, point1, point2);
    holst.DrawLine(pen_white, point2, point3);
    holst.DrawLine(pen_white, point3, point1);
    FractalKoh(point1, point2, point3, 7);
    FractalKoh(point2, point3, point1, 7);
    FractalKoh(point3, point1, point2, 7);

}
1 Answers

Windows Form has an event "Size Changed". Inside the event handler method you can get width and height with following:

private void Form1_SizeChanged(object sender, EventArgs e)

    {
        int width= this.Width;
        int height= this.Height;
       
        double widthCoeficient = initialWidth / width;
        double heightCoeficient = initialHeight / height;
    }

In your form declare to global variables.

    private int initialWidth;
    private int initialHeight;

in form_load initialize this variable

        initialHeight = this.Height;
        initialWidth = this.Width;
Related