저는 이것을 form1에 두었습니다. label2에 타이머 간격을 지정합니다. 기본 간격은 100ms입니다.단위를 초당 프레임으로 변환하려면 어떻게해야합니까?
label2.Text = timer1.Interval.ToString();
을 그리고 이것은을 Form1에 마우스 휠 이벤트 :
private void Form1_MouseWheel(object sender, MouseEventArgs e)
{
PbsWheel pbsw = new PbsWheel(pbs, pb, e.Delta, label2);
}
그리고이 클래스 Pbswheel 입니다 나는 사용자가이를보고 초당 프레임으로 간격 속도를 변경할 것이라고합니다 pbs는 pictureBoxes의 배열이고 pb는 pictureBox입니다.
using System;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WeatherMaps
{
class PbsWheel
{
public PbsWheel(AnimatedPictureBox.AnimatedPictureBoxs[] pbs, AnimatedPictureBox.AnimatedPictureBoxs pb, int delta,Label label2)
{
for (int i = 0; i < pbs.Length; i++)
{
if (delta > 0)
{
if (pbs[i].AnimateRate < 5000)
{
if (pbs[i].AnimateRate < 1000)
{
pbs[i].AnimateRate += 100;
label2.Text = (pbs[i].AnimateRate/(double)1000).ToString();
}
else
{
pbs[i].AnimateRate += 1000;
label2.Text = (pbs[i].AnimateRate/1000).ToString();
}
}
}
else
{
if (pbs[i].AnimateRate > 1000)
{
pbs[i].AnimateRate -= 1000;
label2.Text = (pbs[i].AnimateRate/1000).ToString();
}
else
if (pbs[i].AnimateRate <= 1000 && pbs[i].AnimateRate > 100)
{
pbs[i].AnimateRate -= 100;
label2.Text = (pbs[i].AnimateRate/(double)1000).ToString();
}
}
}
if (delta > 0)
{
if (pb.AnimateRate < 5000)
{
if (pb.AnimateRate < 1000)
{
pb.AnimateRate += 100;
label2.Text = (pb.AnimateRate/(double)1000).ToString();
}
else
{
pb.AnimateRate += 1000;
label2.Text = (pb.AnimateRate/1000).ToString();
}
}
}
else
{
if (pb.AnimateRate > 1000)
{
pb.AnimateRate -= 1000;
label2.Text = (pb.AnimateRate/1000).ToString();
}
else
if (pb.AnimateRate <= 1000 && pb.AnimateRate > 100)
{
pb.AnimateRate -= 100;
label2.Text = (pb.AnimateRate/(double)1000).ToString();
}
}
}
}
}
내가 (이 100ms) 라벨 2 (100)에 표시되는 프로그램을 실행하는 메신저 그리고 나는 그것의 최소 0.1 가장 빠르게 갈 휠을 아래로 이동할 때 때 지금 무엇을. 이동할 때 : 01,0.2,0.3 .... 0.9,1,2,3,4,5 최대 속도는 5 초입니다.
각 사진 상자의 이미지가 속도를 변경하면 애니메이션/루프로 표시됩니다.
AnimateRate는이 클래스에서이 클래스를 사용하여 이미지의 애니메이션/루프에 대한 각 pictureBox에 대한 타이머를 만들고 AnimateRate는 마우스 휠을 움직일 때의 속도를 설정합니다. Form1에있는
using System;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DannyGeneral;
namespace WeatherMaps
{
class AnimatedPictureBox
{
//Use this custom PictureBox for convenience
public class AnimatedPictureBoxs : PictureBox
{
public static bool images;
List<string> imageFilenames;
Timer t = new Timer();
public AnimatedPictureBoxs()
{
images = false;
AnimateRate = 100; //It's up to you, the smaller, the faster.
t.Tick += Tick_Animate;
}
public int AnimateRate
{
get { return t.Interval; }
set { t.Interval = value; }
}
public void Animate(List<string> imageFilenames)
{
this.imageFilenames = imageFilenames;
t.Start();
}
public void StopAnimate()
{
t.Stop();
i = 0;
}
int i;
private void Tick_Animate(object sender, EventArgs e)
{
if (images == true)
{
imageFilenames = null;
}
if (imageFilenames == null)
{
return;
}
else
{
try
{
if (i >= imageFilenames.Count)
{
i = 0;
}
else
{
Load(imageFilenames[i]);
i = (i + 1) % imageFilenames.Count;
}
}
catch (Exception err)
{
Logger.Write(err.ToString());
}
}
}
}
}
}
타이머 1 난 그냥 라벨 2 텍스트가 타이머 1의 기본 간격 수 있지만, 타이머 1을 사용하지 않는 메신저 것이다 않았다 사용되지 않습니다.
코드는 약간 길지만 모두 연결되어 있습니다.
이제 속도를 변경하는 대신 초당 프레임 수를 변경하고 싶습니다. 초당
http://en.wikipedia.org/wiki/Frequency for more :) – Steve