views:

80

answers:

1

Hi to all dear!!

I have a form which contains one tab contol with 3 tabs. How do I refresh only one tab page in the form with a backgroundworker thread and not refresh the other tabs?

+2  A: 

Here is how to update a specific tab page in a tabcontrol:

private delegate void RefreshTabPageDelegate(int tabPage);

public static void RefreshTabPageThreadSafe(int tabPage)
{
  if (tabControl.InvokeRequired)
  {
    tabControl.Invoke(new RefreshTabPageDelegate(RefreshTabPageThreadSafe), new object[] { tabPage });
  }
  else
  {
    if(tabControl.TabPages.Count > tabPage)
    {
      tabControl.TabPages[tabPage].Refresh();
    }
  }
}

Call it like this:

// thread-safe equivalent of
// tabControl.TabPage[1].Refresh();
RefreshTabPageThreadSafe(1);
SwDevMan81