【问题标题】:How to Stop Timer on Mouse Click when using Web Browser in Windows Forms?在 Windows 窗体中使用 Web 浏览器时如何在鼠标单击时停止计时器?
【发布时间】:2013-12-19 07:39:13
【问题描述】:

我创建了一个 Windows 窗体,在其中添加了WebKit Browser。我创建了一个计时器,每 5 秒后将用户发送到'PlayVideo' Form。 如果用户单击表单,我希望计时器停止并重新启动。 我面临的问题是它没有检测到表单点击。如果我从 FORM 中删除 WebKit 浏览器,它会检测到表单点击并重置计时器。 请告诉我一种检测 WebKitBrowser 上鼠标点击的方法。

   private void timer1_Tick(object sender, EventArgs e)
    {
        videoplayer videoplayer = new videoplayer();
        videoplayer.Show();

        this.Hide();

        timer1.Stop();

    }

    private void Form1_Load(object sender, EventArgs e)
    {
        timer1.Start();

    }

    private void Form1_MouseDoubleClick(object sender, MouseEventArgs e)
    {
        timer1.Stop();

        timer1.Start();

    }

【问题讨论】:

    标签: c# winforms visual-studio-2010 timer webkit


    【解决方案1】:

    看起来您需要一些表单范围的鼠标事件。实际上,您可以处理 WebBrowserDoubleClick 事件,但是我已经尝试过了,并且不支持该事件(和其他一些鼠标事件)。因此,您可以尝试在IMessageFilter 的帮助下实现以下窗体范围的鼠标事件处理程序:

    public partial class Form1 : Form, IMessageFilter
    {
        public Form1()
        {
            InitializeComponent();
            Application.AddMessageFilter(this);
        }
        //...
        //method implementation of the interface IMessageFilter
        public bool PreFilterMessage(ref Message m)
        {
            //WM_LBUTTONDBLCLK = 0x203
            if (m.Msg == 0x203) {
                //your code goes here...
                timer1.Stop();
                timer1.Start();
            }
            return false;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2023-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-10
      • 2021-03-26
      • 2020-08-22
      • 2019-03-16
      • 2023-04-05
      相关资源
      最近更新 更多