C# winform pictureBox如何突出显示,放大并给pictureBox边框变色

时间:2023-03-09 00:05:34
C# winform pictureBox如何突出显示,放大并给pictureBox边框变色
  1. PictureBox old = null;
  2. private void pictureBox2_Click(object sender, EventArgs e)
  3. {
  4. PictureBox p = (PictureBox)sender;
  5. if (p == old) return;
  6. if (old != null)
  7. {
  8. old.Width -= 10;
  9. old.Height -= 10;
  10. old.Location = new Point(old.Location.X + 5, old.Location.Y + 5);
  11. }
  12. old = p;
  13. p.Width += 10;
  14. p.Height += 10;
  15. p.Location = new Point(p.Location.X - 5, p.Location.Y - 5);
  16. p.BringToFront();
  17. }
  18. private void pictureBox2_Paint(object sender, PaintEventArgs e)
  19. {
  20. PictureBox p = (PictureBox)sender;
  21. if (p == old)
  22. {
  23. Pen pp = new Pen(Color.Red);
  24. e.Graphics.DrawRectangle(pp, e.ClipRectangle.X, e.ClipRectangle.Y, e.ClipRectangle.X + e.ClipRectangle.Width - 1, e.ClipRectangle.Y + e.ClipRectangle.Height - 1);
  25. }
  26. }