user143653
user143653

Reputation:

about refresh UI !

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?

Upvotes: 0

Views: 2608

Answers (1)

SwDevMan81
SwDevMan81

Reputation: 49988

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);

Upvotes: 2

Related Questions