Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float actualHeight = myImg.Height;
- float actualWidth = myImg.Width;
- float imgRatio = actualWidth / actualHeight;
- float maxRatio = (float)this.Width / this.Height;
- if(imgRatio!=maxRatio)
- {
- if (imgRatio < maxRatio)
- {
- imgRatio = this.Height / actualHeight;
- actualWidth = imgRatio * actualWidth;
- actualHeight = this.Height;
- }
- else
- {
- imgRatio = this.Width / actualWidth;
- actualHeight = imgRatio * actualHeight;
- actualWidth = this.Width;
- }
- }
- pictureBox.Size=new Size((int)actualWidth,(int)actualHeight);
- pictureBox.Location = new Point((int)((this.Width - actualWidth) / 2), (int)((this.Height - actualHeight) / 2));
Add Comment
Please, Sign In to add comment