利用控件名称获取控件对象

string strLabelNum = "lab_" + iNum.ToString();

Control[] cLabel = pnl.Controls.Find(strLabelNum, true);

Label lblTop = (Label)cLabel[0];

lblTop.Left = pnl.Width / 2 - 5;

lblTop.Top = pnl.Height / 2 - 5;

lblTop.Text = Convert.ToString(picnum.iPageFirstNum + iNum - 1);

lblTop.BringToFront(); lblTop.Refresh();

 

wpf中:

  this.FindName("控件名称");

posted @ 2012-03-23 14:27  @张凯@  阅读(317)  评论(0编辑  收藏  举报