项目需要,学了一下timer控件,很好用,特此分享。。。
以下是项目界面,详设,以及代码截图
1.项目界面截图
2.详设截图
3.数据和刷新时间代码截图
4.滚动状态代码截图
5.停止滚动代码截图
6.停止取样代码
7.设置刷新时间
8.双击触发方法
设计代码(方便你我他)
/// <summary>
/// 叶航宇
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
string nowTimeYe = "";
private void FormScheduleTracking_Load(object sender, EventArgs e)
{
//timer1.Interval = 1000;
RefreshData();
}
/// <summary>
/// 查询数据+刷新时间
/// </summary>
private void RefreshData()
{
DataSet dsPackageInventoryIn = PackageManageAPI.PackageManageService.GetLookYe();
dsTv_Irder_Ianufacture_Info1.Merge(dsPackageInventoryIn);
nowTimeYe = System.DateTime.Now.ToString();
labDateTime.Text = nowTimeYe;
}
/// <summary>
/// 设置按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnSetting_Click(object sender, EventArgs e)
{
setWindowYe swy = null;
if (swy == null || swy.IsDisposed)
{
swy = new setWindowYe();
swy.Show();
this.RefreshData();
}
else {
swy.Activate();
}
}
/// <summary>
/// 停止滚动
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnStopspeed_Click(object sender, EventArgs e)
{
if (timer2.Enabled == true)//状态切换
{
timer2.Enabled = false;
btnStopspeed.Text = "滚动";
}
else if(timer2.Enabled == false){
timer2.Enabled = true;
btnStopspeed.Text = "停止滚动";
}
}
/// <summary>
/// 停止取数
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnStopgetting_Click(object sender, EventArgs e)
{
if (timer1.Enabled == true && timer2.Enabled == true) {
timer1.Enabled = false;
timer2.Enabled = false;
btnStopgetting.Text = "取样";
}
else if (timer1.Enabled == true && timer2.Enabled == false) {
timer1.Enabled = false;
timer2.Enabled = false;
btnStopgetting.Text = "取样";
}
else if (timer1.Enabled == false && timer2.Enabled == true)
{
timer1.Enabled = false;
timer2.Enabled = false;
btnStopgetting.Text = "取样";
}
else if (timer1.Enabled == false && timer2.Enabled == false) {
timer1.Enabled = true;
timer2.Enabled = true;
btnStopgetting.Text = "停止取样";
}
}
/// <summary>
/// 滚动状态
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void scroll(object sender, EventArgs e)
{
if (gdvTrack.DataRowCount.ToString().Length > 0)//如果有数据
{
if (this.gdvTrack.IsLastRow)//如果最后一行
{
this.gdvTrack.MoveFirst();//滚动到第一行
}
else
{
this.gdvTrack.MoveNextPage();//滚动到下一页
}
}
}