public void AddImage(string imageFilePath, Size size, Point position) { var roundCornerBox = new RoundCornerS(); //TextBox myText = new TextBox(); var pictBox = new PictureBox(); roundCornerBox.Controls.Add(pictBox); pictBox.Dock = DockStyle.Fill; //pictBox.Location = position;// new Point(25, 25); // Sets up an image object to be displayed. /* * if (MyImage != null) * { * MyImage.Dispose(); * } */ var path = imageFilePath;// "D:\\nobuoka\\Pictures\\127e16d38f9dc29c71cee6b01f067cf6.jpeg"; // Stretches the image to fit the pictureBox. pictBox.SizeMode = PictureBoxSizeMode.Zoom; try { var maxSize = rand.Next(500, 800); var image = new Bitmap(path); var rat = (double)Math.Max(1, Math.Max((double)image.Width / maxSize, (double)image.Height / maxSize)); var imageSize = new Size((int)(image.Width / rat), (int)(image.Height / rat)); pictBox.Image = (Image)image; var pos = new Point( rand.Next(-imageSize.Width / 3, Bounds.Width - imageSize.Width + imageSize.Width / 3), rand.Next(-imageSize.Height / 3, Bounds.Height - imageSize.Height + imageSize.Height / 3)); roundCornerBox.ClientSize = imageSize; // new Size(250, 250); roundCornerBox.Location = pos; // new Point(25, 25); if (this.Controls.Count > 40) { var cont = this.Controls[this.Controls.Count - 1]; // GetChildIndex(this.Controls.Count - 1); this.Controls.RemoveAt(this.Controls.Count - 1); cont.Dispose(); } this.Controls.Add(roundCornerBox); roundCornerBox.BringToFront(); } catch (Exception err) { // do nothing // 画像じゃないファイルをあれしようとしてエラーが発生することがある } }
public void AddImage(string imageFilePath, Size size, Point position) { var roundCornerBox = new RoundCornerS(); //TextBox myText = new TextBox(); var pictBox = new PictureBox(); roundCornerBox.Controls.Add(pictBox); pictBox.Dock = DockStyle.Fill; //pictBox.Location = position;// new Point(25, 25); // Sets up an image object to be displayed. /* if (MyImage != null) { MyImage.Dispose(); } */ var path = imageFilePath;// "D:\\nobuoka\\Pictures\\127e16d38f9dc29c71cee6b01f067cf6.jpeg"; // Stretches the image to fit the pictureBox. pictBox.SizeMode = PictureBoxSizeMode.Zoom; try { var maxSize = rand.Next(500, 800); var image = new Bitmap(path); var rat = (double)Math.Max(1, Math.Max((double)image.Width / maxSize, (double)image.Height / maxSize)); var imageSize = new Size((int)(image.Width / rat), (int)(image.Height / rat)); pictBox.Image = (Image)image; var pos = new Point( rand.Next(-imageSize.Width / 3, Bounds.Width - imageSize.Width + imageSize.Width / 3), rand.Next(-imageSize.Height / 3, Bounds.Height - imageSize.Height + imageSize.Height / 3)); roundCornerBox.ClientSize = imageSize;// new Size(250, 250); roundCornerBox.Location = pos;// new Point(25, 25); if (this.Controls.Count > 40) { var cont = this.Controls[this.Controls.Count - 1]; // GetChildIndex(this.Controls.Count - 1); this.Controls.RemoveAt(this.Controls.Count - 1); cont.Dispose(); } this.Controls.Add(roundCornerBox); roundCornerBox.BringToFront(); } catch (Exception err) { // do nothing // 画像じゃないファイルをあれしようとしてエラーが発生することがある } }