2013/01/29(Tue) 12:59:27 編集(投稿者)
//継承クラス
public class ExpandClass : BaseClass
{
public ExpandClass()
{
clsTimer =
new DispatcherTimer(TimeSpan.FromMilliseconds(1000),
DispatcherPriority.Send, new EventHandler(base.dispatcherTimer_Tick),
Dispatcher.CurrentDispatcher);
clsTimer.Stop();
iCounter = 0;
}
//タイマー作り直し
public void RemakeTimer()
{
//これを消すと多重に動く
clsTimer.Tick -= new EventHandler(base.dispatcherTimer_Tick);
//再作成
clsTimer =
new DispatcherTimer(TimeSpan.FromMilliseconds(1000),
DispatcherPriority.Send, new EventHandler(base.dispatcherTimer_Tick),
Dispatcher.CurrentDispatcher);
clsTimer.Stop();
iCounter = 0;
}
//タイマー開始
public void StartTimer()
{
if (clsTimer.IsEnabled == false)
{
clsTimer.Interval = TimeSpan.FromMilliseconds(1000);
clsTimer.Start();
}
}
//タイマー終了
public void StopTimer()
{
if (clsTimer.IsEnabled == true)
{
clsTimer.Stop();
}
}
//タイマーが実行中かどうか
public bool IsTimerStarted()
{
return clsTimer.IsEnabled;
}
}
//
public class BaseClass
{
protected DispatcherTimer clsTimer = null;
protected int iCounter = 0;
private Label clsBindLabel = null;
//ラベルにカウンタ表示
protected void dispatcherTimer_Tick(object sender, EventArgs e)
{
iCounter++;
if(clsBindLabel != null)
{
clsBindLabel.Content = iCounter.ToString();
}
}
public void SetLabel(Label clsLabel)
{
clsBindLabel = clsLabel;
}
}