C# Form 焦點[讓窗體獲得焦點,一定會有您用到的時候]
C# Form 焦點[讓窗體獲得焦點,一定會有您用到的時候]
資料來源: https://www.itread01.com/content/1547512584.html
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace Test { public partial class PlayVoice : Form { public PlayVoice() { InitializeComponent(); } [System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "GetForegroundWindow", CharSet = System.Runtime.InteropServices.CharSet.Auto, ExactSpelling = true)] public static extern IntPtr GetF(); //獲得本窗體的控制代碼 [System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "SetForegroundWindow")] public static extern bool SetF(IntPtr hWnd); //設定此窗體為活動窗體 private void timer1_Tick(object sender, EventArgs e) { if (this.Handle != GetF()) //如果本視窗沒有獲得焦點 SetF(this.Handle); //設定本視窗獲得焦點 } } }
One thought on “C# Form 焦點[讓窗體獲得焦點,一定會有您用到的時候]”
C# 表單/視窗 焦點(Focus) WINDOWS API