c# winforms按比例更改图形缩放窗口

ruoxqz4g  于 2022-11-17  发布在  C#
关注(0)|答案(1)|浏览(211)

当我按下按钮时,我画了一个koch雪花。但是请告诉我,当我改变窗口比例时,如何使雪花按比例改变大小?

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);

}
oyjwcjzk

oyjwcjzk1#

Windows窗体有一个“Size Changed”事件。在该事件处理程序方法中,可以使用以下命令获取宽度和高度:

private void Form1_SizeChanged(object sender, EventArgs e)

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

在表单中宣告为全局变量。

private int initialWidth;
    private int initialHeight;

在form_load中初始化此变量

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

相关问题