【问题标题】:Enable/Disable GIF in picturebox onhover [duplicate]在图片框悬停时启用/禁用 GIF [重复]
【发布时间】:2021-12-18 11:06:56
【问题描述】:

GIF 默认在表单加载时播放,但我希望它在表单加载时停止动画,所以我添加了 pictureBox1.Enabled = false; 但 MouseHover 或 MouseEnter 没有努力恢复 gif 播放。

【问题讨论】:

标签: c# winforms gif onmouseover


【解决方案1】:

将 gif 和 gif 都保存为资源中的图像。然后在表单加载时在图片框中设置 gif 图像,要显示 gif,请在鼠标悬停事件中将其加载到图片框中。同样,当鼠标离开时,将 gif 图像设置为图片框,如代码中所做的那样。

 public Form1()
            {
                InitializeComponent();
                pictureBox1.Image = Properties.Resources.download__2_; //Gif Image
            }
    
            private void pictureBox1_MouseHover(object sender, System.EventArgs e)
            {
                pictureBox1.Image = Properties.Resources.fa9e27a7534060df383ab54354fcead3; //Actual Gif
            }
    
            private void pictureBox1_MouseLeave(object sender, System.EventArgs e)
            {
                pictureBox1.Image = Properties.Resources.download__2_; //Gif Image
            }

【讨论】:

    【解决方案2】:

    您可以使用表单/容器的mouemove来检查图片框是否在光标下,然后激活它。

    public Form1()
    {
        InitializeComponent();
        pictureBox1.Enabled = false;
    }
    
    private void pictureBox1_MouseEnter(object sender, EventArgs e)
    {
        //MessageBox.Show("enabled");
    }
    
    private void Form1_MouseMove(object sender, MouseEventArgs e)
    {
        if (!pictureBox1.Enabled)
        {
            pictureBox1.Enabled = (GetChildAtPoint(e.Location) == pictureBox1);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-17
      • 2015-05-12
      相关资源
      最近更新 更多