weixin_44097963 2019-05-31 01:36 采纳率: 66.7%
浏览 580
已采纳

winform c# 可不可以将某个窗体的所有内容以图片形式显示在另一个窗体?

图片说明
这是我自己制作的一个窗体form1(使用的是label 和boxlist)
1.想将这个窗体的内容以图片形式或者其他什么办法,copy到form2
2.form2内容可以以图片或者其他形式,选着路径储存在电脑里。(易于打开例如excel,txt,图片等格式)。
初学者,学校作业,请附上代码,或者详细解说。

  • 写回答

2条回答

  • threenewbee 2019-05-31 09:40
    关注

    如果问题解决,请点我回答左上角的采纳和向上的箭头,采纳后留下email,把完整代码给你

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Drawing.Imaging;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace Q763937
    {
        public partial class Form1 : Form
        {
    
            [System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
            private static extern bool BitBlt
            (
                IntPtr hdcDest,    //目标DC的句柄
                int nXDest,        //目标DC的矩形区域的左上角的x坐标
                int nYDest,        //目标DC的矩形区域的左上角的y坐标
                int nWidth,        //目标DC的句型区域的宽度值
                int nHeight,       //目标DC的句型区域的高度值
                IntPtr hdcSrc,     //源DC的句柄
                int nXSrc,         //源DC的矩形区域的左上角的x坐标
                int nYSrc,         //源DC的矩形区域的左上角的y坐标
                System.Int32 dwRo  //光栅的处理数值
            );
    
            [System.Runtime.InteropServices.DllImportAttribute("user32.dll")]
            public extern static IntPtr FindWindow(string lpClassName, string lpWindowName);
    
            [System.Runtime.InteropServices.DllImportAttribute("user32.dll")]
            public static extern int GetWindowRect(IntPtr hWnd, out Rectangle lpRect);
    
            [System.Runtime.InteropServices.DllImportAttribute("user32.dll")]
            public extern static IntPtr GetDC(IntPtr hWnd);
    
            [System.Runtime.InteropServices.DllImportAttribute("user32.dll")]
            public extern static int ReleaseDC(IntPtr hWnd, IntPtr hDC);
    
            [System.Runtime.InteropServices.DllImport("user32.dll")]
            static extern bool GetClientRect(IntPtr hWnd, out Rectangle lpRect);
    
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Button1_Click(object sender, EventArgs e)
            {
                Rectangle rect;
                IntPtr hwnd1 = this.Handle;
                //GetWindowRect(hwnd1, out rect);  //获得目标窗体的大小
                GetClientRect(hwnd1, out rect);
                Bitmap frmimg = new Bitmap(rect.Width, rect.Height);
                Graphics g1 = Graphics.FromImage(frmimg);
                IntPtr hdc1 = GetDC(hwnd1);
                IntPtr hdc2 = g1.GetHdc();  //得到Bitmap的DC
                BitBlt(hdc2, 0, 0, rect.Width, rect.Height, hdc1, 0, 0, 13369376);
                g1.ReleaseHdc(hdc2);  //释放掉Bitmap的DC
                var f2 = Application.OpenForms["Form2"] as Form2;
                if (f2 == null)
                    f2 = new Form2();
                f2.pictureBox1.Image = frmimg;
                SaveFileDialog sfd = new SaveFileDialog();
                if (sfd.ShowDialog() == DialogResult.OK)
                    frmimg.Save(sfd.FileName, ImageFormat.Jpeg);
                f2.Show();
            }
        }
    }
    
    

    图片说明

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 ubuntu系统下挂载磁盘上执行./提示权限不够
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)