首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >焦点形式按下键

焦点形式按下键
EN

Stack Overflow用户
提问于 2014-02-18 10:22:13
回答 2查看 102关注 0票数 1

我正在尝试使用youtube嵌入式播放器(轴激波闪光灯),并利用它制作一个很好的程序。

问题是,我正在尝试实现一个按钮,该按钮将重播/下一个/之前的当前视频。

我的自动取款机是:

代码语言:javascript
复制
 private void btReplay_Click(object sender, EventArgs e)
    {
        if (!youtubePlayer.Focus())
        {
            youtubePlayer.Focus();
            SendKeys.Send("0");
        }
        else
        {
            SendKeys.Send("0");
        }
        this.BringToFront();
    }

按“0”键可以从一开始就重放视频。只有它还会使窗体在其他打开的窗口之间消失。

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

有什么想法吗?

另外,如果有人对此有任何经验,我也想发挥如何启用自动播放下一个视频时,使用‘结束’键。我知道autoplay=1函数,但在按END键时,它似乎不起作用。

编辑:使用WinForms

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-03-24 15:25:54

代码语言:javascript
复制
this.BringToFront();
this.TopMost = true;

为我工作,傻瓜,我没想过这个。

票数 0
EN

Stack Overflow用户

发布于 2014-02-18 10:35:42

您没有指定是使用winForms还是WPF。这个片段是给winforms的。

在这里,我给出了一个静态方法,它强制任何给定的形式出现在前面:

代码语言:javascript
复制
    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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21850723

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档