日期:2014-05-20  浏览次数:21046 次

一组动态生成的Label控件显示投票数,为什么显示的票数不更新?
//动态生成Label控件
private   void   DisplayVotes()
{

Poll   myPoll   =   new   Poll(@ "D:\Solutions\PollSZWA\Poll.xml ");
int   myAnswerCount   =   myPoll.AnswerCount;
totalVotesLabel.Text   =   myPoll.GetTotalVotes().ToString();
voteLabel   =   new   Label[myAnswerCount];
for(int   i=0;i <=(myAnswerCount/6);i++)
{
for(int   j=0;j <6;j++)
{
if((i*6+j) <myAnswerCount)
{
//显示投票数据
Label   myLabel   =   new   Label();
myLabel.Location     =   new   Point(8+j*160+Bwidth,120+(80*i));
myLabel.Size   =   new   Size(Pwidth,Pheight);
myLabel.Font     =   new   Font( "宋体 ",14);
myLabel.TextAlign   =   System.Drawing.ContentAlignment.MiddleCenter;;
myLabel.Text   =   myPoll.Votes[i*6+j].ToString();
voteLabel[i]   =   myLabel;
this.tabControlPoll.TabPages[0].Controls.Add(myLabel);
}
}
}


}
//投一票以后更新显示
private   void   answerButton_Click(object   sender,   System.EventArgs   e)
{
//点击投票数据
Button   clickedButton   =   sender   as   Button;
int   vote   =   int.Parse(clickedButton.Name.ToString());
Poll   myPoll   =   new   Poll(@ "D:\Solutions\PollSZWA\Poll.xml ");
myPoll.Vote(vote);
//显示票数
DisplayVotes();
}

------解决方案--------------------
跟踪一下吧
------解决方案--------------------
帮LZ顶
------解决方案--------------------
恩 跟踪 应该很容易找到问题了就