Scaling Picturebox does not change image at all

前端 未结 1 1354
温柔的废话
温柔的废话 2021-01-23 19:02

I\'m using a picturebox to create a visual of an instance of my truss class. I\'m creating the visual by drawing directly onto the picture box in the paint event. The method loo

1条回答
  •  清歌不尽
    2021-01-23 19:41

    Call ScaleTransform before you do your drawing. You can calculate the desired scale factor like this:

    // place this code after the calculation of maxWidth and maxHeight
    // but before the drawing code
    PictureBox p = (PictureBox)sender;
    float scaleFactor = Math.Min(
        ((float)p.Width) / maxWidth,
        ((float)p.Height) / maxHeight
    );
    
    g.ScaleTransform(scaleFactor, scaleFactor);
    

    0 讨论(0)
提交回复
热议问题