C#中如何从远程获取面板屏幕

How to get panel screen from remote in c#

我创建了一个远程桌面应用程序。但现在我想创建一个远程 doolder 应用程序。但它有一个问题。现在我无法解决这个问题。 我无法获得指定的面板边界。它显示一块屏幕尺寸。我要获取面板内容

代码如下:

namespace client
{
    public partial class Form1 : Form
    {
        private readonly TcpClient client = new TcpClient();
        private NetworkStream mainStream;
        private int portNumber;

        private Image GrabDesktop()
        {
           // Rectangle bounds = Screen.PrimaryScreen.Bounds;
            Rectangle bounds = panel1.Bounds;

            Bitmap screenshot = new Bitmap(bounds.Width, bounds.Height, PixelFormat.Format32bppArgb);
            Graphics graphics = Graphics.FromImage(screenshot);
            graphics.CopyFromScreen(bounds.X,bounds.Y,0,0,bounds.Size, CopyPixelOperation.SourceCopy);

            return screenshot;
        }

        private void SendDesktopImage()
        {

            BinaryFormatter binFormatter = new BinaryFormatter();
            mainStream = client.GetStream();
            binFormatter.Serialize(mainStream, GrabDesktop());

        }

        public Form1()
        {
            InitializeComponent();
        }
    }
}

使用Control.DrawToBitmap

var screenshot = new Bitmap(panel1.Width, panel1.Height);
panel1.DrawToBitmap(screenshot, new Rectangle(0, 0, panel1.Width, panel1.Height));