c# Winform实现图片放大显示功能, 关闭放大窗口图片原样显示

首先,创建2个Form窗体,各放一个pictureBox.



将pictureBox的属性调整为:StretchImage。

form1代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DelegateShow_0319
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            Picture_Show();
        }
        Bitmap bit;//保存图像的Bitmap对象
        private void Picture_Show()
        {
            bit = new Bitmap("123.bmp");//运行前,请拷贝一张图片到当前执行目录。
            this.pictureBox1.Image = bit;//显示图片。
        }
        private void pictureBox1_DoubleClick(object sender, EventArgs e)
        {
            Form2 form2 = new Form2(bit);//构造传参
            form2.Form2_ChangePicture += new Form2.ChangePictureHandler(Form1_Change_Picture);//使用委托,关闭子窗体时,图片回传
            form2.Show();
            this.pictureBox1.Image = null;
        }

        private void Form1_Change_Picture(Bitmap bit)
        {
            this.pictureBox1.Image = bit;
        }
    }

}

需要添加pictureBox的DoubleClick事件。

form2 代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DelegateShow_0319
{
    public partial class Form2 : Form
    {
        public delegate void ChangePictureHandler(Bitmap bit);
        public event ChangePictureHandler Form2_ChangePicture;
        private Bitmap BitImage;
        public Form2(Bitmap bit)
        {
            InitializeComponent();
            BitImage = bit;
            this.pictureBox2.Image = bit;
        }
        private void Form2_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (Form2_ChangePicture != null)
            {
                Form2_ChangePicture(BitImage);
            }
        }
    }

}

需要添加Form2 formClosing事件。

设置好后运行:


然后双击图片:


点击关闭按钮,子窗体退出,原窗体显示图片。


  • 2
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

楚楚3107

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值