日期:2014-05-18  浏览次数:20881 次

C# winform程序中怎样实现tabcontrol控件中的tabpage动态的隔一段时间轮换一页
C# winform程序中怎样实现tabcontrol控件中的tabpage动态的隔一段时间轮换一页

------解决方案--------------------
Dictionary<string,int> dictabPageNameAndTime = new Dictionary<string,int>;

把用户选择的tabPage的name,和要停留的时间放在dictabPageNameAndTime 里,然后放一个timer控件,遍历这个dictabPageNameAndTime 里的元素设置切换和停留时间
------解决方案--------------------
我写的不清楚吗?不要循环 

private List<BoardPage> boardPage = board.GetPageNoIsused(Init.GetHushisiteIdByIp());//获取存放需要显示播放的页号和需要显示的时间
 private int _playIndex = 0;
 private void timer2_Tick(object sender, EventArgs e)
 {
edit.tpPages.SelectedIndex = boardPage[_playIndex].PageNo;
timer2.Stop();
timer2.Interval = boardPage[_playIndex].IsTime;
if(++_playIndex>boardPage.Count())
_playIndex = 0;
timer2.Start();

------解决方案--------------------
EditContentForm edit = null;//子窗体,上面放的是Tabcontrol控件
 点击开始播放按钮
 //开始播放
private void btnStart_Click(object sender, EventArgs e)
{
edit = new EditContentForm();
edit.tsmInsert.Visible = false;//播放的时候禁用插入的右键菜单
edit.WindowState = FormWindowState.Maximized;
StartServerTimerElapsed();
timer2.Start();
}

private int _playIndex = 0;
private List<BoardPage> boardPage = BoardPageDAL.GetPageNoIsused(Init.GetHushisiteIdByIp());//获取存放需要显示播放的页号和显示时间,存放的pageNo从1开始
//播放控制(需要播放哪些页面)
private void timer2_Tick(object sender, EventArgs e)
{
 
 if (_playIndex > boardPage.Count - 1)
{
_playIndex = 0;
}
StartServerTimerElapsed();



public delegate void StartServerTimerElapsedHandler();
public void StartServerTimerElapsed()
{
if (tabControl1.InvokeRequired)
{
StartServerTimerElapsedHandler delegateMethod = new StartServerTimerElapsedHandler(StartServerTimerElapsed);
this.Invoke(delegateMethod);
}
else
{
edit.tpPages.SelectedIndex = boardPage[_playIndex].PageNo - 1;//selectIndex索引从0开始
timer2.Interval = boardPage[_playIndex].IsTime;
_playIndex++;
}
}
------解决方案--------------------
给lz一个个人经验吧
timer编程的时候不要直接执行需要的语句,timer内加上判断后再执行。timer外定义一个执行次数的count,然后timer内判断count次数是否是你需要的timer间隔时常*count等于需等待时长。
大致就是类似这样:

C# code

private count = 0;
 private void timer2_Tick(object sender, EventArgs e)
 {
if(count=yourcount)
{
todo;
}
else
{
count++;
}
}