المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Smooth Moving of TableLayoutPanel control [modified]



C# Programming
10-10-2009, 02:00 AM
Hi, all,
In my Windows Form, there is a TableLayoutPanel control having about 15 rows(column count is not taken into account) and a Button, and in the button_Click event, there are two methods RemoveUpperRow() and AddNewRow() inserted as follows:

modified: Sorry, just noticed there are sth else I need to provide before you check my codes.There are also one label in each cells in the first column, and this is the reason I am able to do rolling by the following codes. http://www.barakasoft.com/script/Forums/Images/smiley_tongue.gif

private void RemoveUpperRow()
{
Control c = tlp_MouseArea.GetControlFromPosition(0, 1);
tlp_MouseArea.Controls.Remove(c);
tlp_MouseArea.RowStyles.RemoveAt(0);
//rolling all rows up by 1...
for (int i = 1; i < tlp_MouseArea.RowCount; i++)
{
c = tlp_MouseArea.GetControlFromPosition(0, i+1);
if (c == null)
break;
TableLayoutPanelCellPosition controlPosition = new TableLayoutPanelCellPosition(0, i);
tlp_MouseArea.SetCellPosition(c, controlPosition);
}
}

private void AddNewRow()
{
tlp_MouseArea.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 18F));

#region new label and its settings
Label lbl_New = new Label();
if (int.Parse(tlp_MouseArea.GetControlFromPosition(0, 13).Text) < 15)
{
lbl_New.Text = Convert.ToString(int.Parse(tlp_MouseArea.GetControlFromPosition(0, 13).Text) + 1);
}
else
lbl_New.Text = "0";
lbl_New.Dock = DockStyle.Fill;
lbl_New.Font = new System.Drawing.Font("Tahoma", 8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel, ((byte)(0)));
lbl_New.TextAlign = ContentAlignment.MiddleCenter;
#endregion

TableLayoutPanelCellPosition pos = new TableLayoutPanelCellPosition(0, 14);
tlp_MouseArea.SetCellPosition(lbl_New, pos);
tlp_MouseArea.Controls.Add(lbl_New);
}


My problem is that it works fine, but it seems to be too slow, and the whole form is flicking till the end, that's something nobody would want to see. So, is there anything wrong with my code? Would you give me some suggestions? Your kind help is so much appreciated!

Liang

modified on Friday, October 9, 2009 7:26 AM