关键时刻重点关注

时间:2014-02-18 10:22:13

标签: c# winforms youtube focus

我正在尝试使用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'键可以从头开始播放视频。只有它也使表单在其他打开的窗口之间消失。

如你所见,我尝试过使用它,但它不起作用。

有什么想法吗?

此外,如果有任何人有这方面的经验,我还想玩如何使用'END'键启用自动播放下一个视频。我知道autoplay = 1函数,但按END键似乎不起作用。

编辑:使用WinForms btw

2 个答案:

答案 0 :(得分: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);

答案 1 :(得分:0)

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

为我工作,愚蠢我没有想到这一点。