如果vncSharp.RemoteDesktop库中没有GetDesktopSize()方法,您可以尝试使用其他方法来获取服务器屏幕的大小。以下是一种可能的解决方案:

  1. 使用Screen类的属性来获取屏幕的大小。可以使用Screen.PrimaryScreen.Bounds属性来获取主屏幕的大小,或者使用Screen.AllScreens属性来获取所有屏幕的大小。
using System.Windows.Forms;

// 获取主屏幕的大小
Rectangle screenSize = Screen.PrimaryScreen.Bounds;
int screenWidth = screenSize.Width;
int screenHeight = screenSize.Height;

// 获取所有屏幕的大小
Screen[] allScreens = Screen.AllScreens;
foreach (Screen screen in allScreens)
{
    int screenWidth = screen.Bounds.Width;
    int screenHeight = screen.Bounds.Height;
    // 处理每个屏幕的大小
}
  1. 如果您无法使用Screen类来获取屏幕大小,可以尝试使用其他库或方法来获取屏幕大小。例如,您可以尝试使用P/Invoke来调用Windows API函数来获取屏幕大小。
using System;
using System.Runtime.InteropServices;

public class ScreenSizeHelper
{
    [DllImport("user32.dll")]
    private static extern IntPtr GetDesktopWindow();

    [DllImport("user32.dll")]
    private static extern IntPtr GetDC(IntPtr hwnd);

    [DllImport("gdi32.dll")]
    private static extern int GetDeviceCaps(IntPtr hdc, int nIndex);

    private const int DESKTOPHORZRES = 8; // 水平分辨率
    private const int DESKTOPVERTRES = 10; // 垂直分辨率

    public static int GetScreenWidth()
    {
        IntPtr desktop = GetDesktopWindow();
        IntPtr hdc = GetDC(desktop);
        int screenWidth = GetDeviceCaps(hdc, DESKTOPHORZRES);
        return screenWidth;
    }

    public static int GetScreenHeight()
    {
        IntPtr desktop = GetDesktopWindow();
        IntPtr hdc = GetDC(desktop);
        int screenHeight = GetDeviceCaps(hdc, DESKTOPVERTRES);
        return screenHeight;
    }
}

// 使用示例
int screenWidth = ScreenSizeHelper.GetScreenWidth();
int screenHeight = ScreenSizeHelper.GetScreenHeight();

请注意,上述代码示例中的方法可能需要进行适当的修改和调整,以符合您的具体需求和环境。

vncSharp.RemoteDesktop库获取服务器屏幕大小解决方案

原文地址: https://www.cveoy.top/t/topic/pZl1 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录