2014-02-18 73 views
1

我正在嘗試使用YouTube嵌入式播放器(axshockwaveflash)並製作一個很好的程序。關鍵窗體上的焦點形式

事情是我試圖實現一個按鈕,將重播/下一個/之前的當前視頻。

我有什麼大氣壓是:

private void btReplay_Click(object sender, EventArgs e) 
    { 
     if (!youtubePlayer.Focus()) 
     { 
      youtubePlayer.Focus(); 
      SendKeys.Send("0"); 
     } 
     else 
     { 
      SendKeys.Send("0"); 
     } 
     this.BringToFront(); 
    } 

的「0」按鍵使得從一開始錄像回放。只有它也會使窗體在其他打開的窗戶之間消失。

正如你所看到的我已經嘗試使用fronttofront,但它不會工作。

有什麼想法?

此外,如果任何人有任何這方面的經驗,我也想播放如何使用'結束'鍵時自動播放下一個視頻。我知道autoplay = 1的功能,但按下END鍵時似乎不起作用。

編輯:使用的WinForms BTW

回答

0
this.BringToFront(); 
this.TopMost = true; 

爲我工作,傻傻的我沒有想到這一點。

0

你沒有指定是否使用的WinForms或WPF。這段代碼是用於winforms的。
在這裏,我給你強制任何形式對前一個靜態方法:

public static void bringWindowToFront(System.Windows.Forms.Form form) 
    { 
     uint foreThread = GetWindowThreadProcessId(GetForegroundWindow(), System.IntPtr.Zero); 
     uint appThread = GetCurrentThreadId(); 
     const uint SW_SHOW = 5; 
     if (foreThread != appThread) 
     { 
      AttachThreadInput(foreThread, appThread, true); 
      BringWindowToTop(form.Handle); 
      ShowWindow(form.Handle, SW_SHOW); 
      AttachThreadInput(foreThread, appThread, false); 
     } 
     else 
     { 
      BringWindowToTop(form.Handle); 
      ShowWindow(form.Handle, SW_SHOW); 
     } 
     form.Activate(); 
    } 

    [System.Runtime.InteropServices.DllImport("user32.dll")] 
    private static extern bool AttachThreadInput(uint idAttach, uint idAttachTo, bool fAttach); 

    [System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)] 
    private static extern bool BringWindowToTop(System.IntPtr hWnd); 

    [System.Runtime.InteropServices.DllImport("kernel32.dll")] 
    public static extern uint GetCurrentThreadId(); 

    [System.Runtime.InteropServices.DllImport("user32.dll")] 
    private static extern System.IntPtr GetForegroundWindow(); 

    [System.Runtime.InteropServices.DllImport("user32.dll")] 
    private static extern uint GetWindowThreadProcessId(System.IntPtr hWnd, System.IntPtr ProcessId); 

    [System.Runtime.InteropServices.DllImport("user32.dll")] 
    private static extern bool ShowWindow(System.IntPtr hWnd, uint nCmdShow); 
+0

似乎是一個很少,只是帶來一個表格是不是?同時對不起編輯第一篇文章說我即將使用WinForms – Bjorn9000

+0

這是我所知道的「最強大」的winforms解決方案,即使在最不利的條件下也會帶來一種形式。我用它來調用托盤圖標點擊一個窗體。否則,表單可能會隱藏在當前活動的應用程序後面。 – Traubenfuchs