/// <summary> /// 获取屏幕缩放比例 /// </summary> /// <returns></returns> public static double GetScale() { double Scale = 1.0; IntPtr DesktopHwnd = Win32Helper.GetDesktopWindow(); using (Graphics DesktopGr = Graphics.FromHwnd(DesktopHwnd)) { IntPtr DesktopHdc = DesktopGr.GetHdc(); int XRes = Win32Helper.GetDeviceCaps(DesktopHdc, (int)Win32Helper.DESKTOPHORZRES); int YRes = Win32Helper.GetDeviceCaps(DesktopHdc, (int)Win32Helper.DESKTOPVERTRES); Scale = (double)XRes / (double)Screen.PrimaryScreen.Bounds.Width; } return(Scale); }
public FormMain() { InitializeComponent(); // 获取缩放比例 scale = Win32Helper.GetScale(); FormBorderStyle = FormBorderStyle.None; WindowState = FormWindowState.Maximized; //本窗体最大化 TransparencyKey = Color.Pink; //背景透明(鼠标穿透) DoubleBuffered = true; //双缓存处理 BackColor = Color.Black; Opacity = 0.75d; TopMost = true; // 画笔 fd = new FormDraw(); //不穿透鼠标透明窗体 //设置不穿透鼠标透明窗体画板鼠标事件为本显示画图窗体鼠标事件进行同步 fd.MouseDown += FormMain_MouseDown; //鼠标按下事件 fd.MouseMove += FormMain_MouseMove; //鼠标移动事件 fd.MouseUp += FormMain_MouseUp; //鼠标弹起事件 //不穿透鼠标透明窗体参数设置如下 fd.WindowState = FormWindowState.Maximized; //最大化 fd.Opacity = 0.1; //背景透明不穿透鼠标 fd.TopMost = true; //让不穿透鼠标透明窗体画板为最上层 gs = CreateGraphics(); //创建窗体画板 pen = new Pen(Color.Red, 5f); //画笔 //fd.Show();//显示 fs = new FormScreenshot(); fs.TopMost = true; //fs.Show(); }