1

我只是对我的代码语法有一点问题。这是我的代码

int frames = Properties.Resources.LOGODENTER.GetFrameCount(FrameDimension.Time);

private void pictureBox1_MouseEnter(object sender, EventArgs e)
{
       pictureBox1.Enabled = true;
        pictureBox1.Image = Properties.Resources.LOGODENTER;
        if (frames == 7)
        {
            pictureBox1.Enabled = false;
        }       
}

private void pictureBox1_MouseLeave(object sender, EventArgs e)
{
        pictureBox1.Enabled = true;
        pictureBox1.Image = Properties.Resources.LOGOLEAVE1;
        if (frames == 6)
        {
            pictureBox1.Enabled = false;
        }
}

基本上我真正想要发生的是,当我的指针进入控件时picturebox1,它会更改其图像,GIF(LOGODENTER)而当鼠标离开其区域时,它会再次更改其图像GIF(LOGOLEAVE1)。我了解 imageAnimator.Animate/StopAnimate 但不知道如何使用它。但我认为你也明白我的代码逻辑是什么。

这是我关于停止 gif 循环的第二篇文章。这是第一个System.Drawing.ImageAnimator.Animate 和 System.Drawing.ImageAnimator.StopAnimate 的解释

4

1 回答 1

0

在我看来,您做得很好。我已使用视频将图像添加到我的资源中,并使用pictureBox以下代码:

private void InitializeComponent()
  {
     this.pictureBox1 = new System.Windows.Forms.PictureBox();
     this.pictureBox1.Location = new System.Drawing.Point(35, 28);
     this.pictureBox1.Name = "pictureBox1";
     this.pictureBox1.Size = new System.Drawing.Size(100, 50);
     this.pictureBox1.TabIndex = 0;
     this.pictureBox1.TabStop = false;
     this.pictureBox1.MouseLeave += new System.EventHandler(this.pictureBox1_MouseLeave);
     this.pictureBox1.MouseEnter += new System.EventHandler(this.pictureBox1_MouseEnter);
     pictureBox1.Image = Properties.Resources.confirmation;
}

private void pictureBox1_MouseEnter(object sender, EventArgs e)
{
     pictureBox1.Image = Properties.Resources.error;

}

private void pictureBox1_MouseLeave(object sender, EventArgs e)
{

     pictureBox1.Image = Properties.Resources.confirmation;
}

它奏效了

让我知道是否缺少任何东西

于 2013-07-21T05:54:32.000 回答