PreviewForm.cs 779 B

1234567891011121314151617181920212223242526272829
  1. using System;
  2. using System.Drawing;
  3. using System.Runtime.InteropServices;
  4. using System.Windows.Forms;
  5. namespace ScreenSaverEf
  6. {
  7. public partial class PreviewForm : Form
  8. {
  9. [DllImport("user32.dll")]
  10. private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
  11. [DllImport("user32.dll")]
  12. private static extern bool GetClientRect(IntPtr hWnd, out Rectangle lpRect);
  13. public PreviewForm(IntPtr hWndParent)
  14. {
  15. InitializeComponent();
  16. SetParent(this.Handle, hWndParent);//设置屏保预览窗口为FrmControl的父窗口
  17. GetClientRect(hWndParent, out var parentRect);
  18. this.Location = new Point(0, 0);
  19. this.Size = parentRect.Size;
  20. }
  21. }
  22. }