using AIProofread.Util; using System; using System.Drawing; using System.Windows.Forms; namespace AIProofread.Controls { public partial class FormMask : Form { public Form myParent; public FormMask(Form myParent) { //InitializeComponent(); this.myParent = myParent; this.FormBorderStyle = FormBorderStyle.None; this.BackColor = Color.Black; this.Opacity = 0.5; // 设置遮罩透明度 this.ShowInTaskbar = false; this.StartPosition = FormStartPosition.Manual; this.WindowState = FormWindowState.Maximized; this.Click += FormMask_Click; //this.TopMost = true; } private void FormMask_Click(object sender, EventArgs e) { User32Util.SetForegroundWindow(myParent.Handle); myParent.Focus(); } public void ShowOverWord() { IntPtr wordHandle = new IntPtr(Globals.ThisAddIn.Application.ActiveWindow.Hwnd); // 获取Word窗口句柄 // User32Util.SetParent(this.Handle, wordHandle); var wordRect = new User32Util.RECT(); User32Util.GetWindowRect(wordHandle, ref wordRect); // 设置遮罩窗体的位置和大小 this.Bounds = new Rectangle(wordRect.Left, wordRect.Top, wordRect.Right - wordRect.Left, wordRect.Bottom - wordRect.Top); this.Show(); } } }