Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7780139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:49:10+00:00 2026-06-01T18:49:10+00:00

C# WinForms: When I call Clear() method of a TabPages: tabControl.TabPages.Clear(); it is also

  • 0

C# WinForms: When I call Clear() method of a TabPages:

tabControl.TabPages.Clear();

it is also firing SelectedIndexChanged event

tabControl_SelectedIndexChanged

. But I don’t want that. Is there a formal or even a hackish way to prevent this being called when I call Clear()? I still want it to be called whenever the user clicks on a tab, but I just don’t want it to automatically get called when somewhere else I am calling the Clear() method.

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T18:49:10+00:00Added an answer on June 1, 2026 at 6:49 pm

    In addition to the comment I made you could make it an Extension Method:

    public static void ClearAllTabPages(this TabControl tc, EventHandler eh)
    {
      tc.SelectedIndexChanged -= eh;
      tc.TabPages.Clear();
      tc.SelectedIndexChanged += eh;
    }
    

    Now you don’t need to remember to unhook and rehook the event handler in every place you would like to clear the TabPages at. You just call:

    tabControl.ClearAllTabPages(tabControl_SelectedIndexChanged);
    

    Note:
    I havn’t tried this code but it should work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a winforms application that includes an Administration form (call it 'adminForm') and
I have a WinForms Application that I want to run at Mono at some
I have 2 winforms, one (call it Form1) contains a background worker, and that
One of my C# Winforms applications randomly displays a pure virtual function call message
In WinForms, you have Control.BeginInvoke() , which means you can marshall a call from
I am using VB.Net WinForms. I would like to call the Adobe Reader 9
QUESTION : In .NET 3.5 WinForms apps, how do I access/call methods in UI
In a simple winform application, I call a function that endlessy create files on
I want to call a JavaScript function through C#, using a WinForm's WebBrowser control.
Winforms-How can I make dialog boxes appear centered on MainForm? That is as opposed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.