VS 2010中的工具箱项目变灰

时间:2011-01-03 18:25:55

标签: visual-studio visual-studio-2008 visual-studio-2010 toolbox

我尝试过多次尝试修复此问题或错误,首先删除C:\ Users \\ AppData \ Local \ Microsoft \ VisualStudio \ x.0

中的.tbd文件

我也试过这个:

Visual Studio“工具”菜单 “选项”子菜单 “Windows窗体设计器”选项卡 “常规选项卡 将“AutoToolboxPopulate”设置为“True”

ToolBox列表仍然没有正确填充,我需要的“BackgroundWorker”组件显示为灰色。有什么想法吗?

3 个答案:

答案 0 :(得分:1)

至少有一种解决方法:在代码中声明BackgroundWorker,但不要忘记妥善处理它:

public class MyForm : Form
{
  private BackgroundWorker bgWorker = null;

  public MyForm()
  {
    InitializeComponent();

    this.bgWorker = new BackgroundWorker; //TODO: set properties and event handlers
  }

  public override void Dispose(bool disposing)
  {
    //TODO: copy from MyForm.Designer.cs and add:
    Backgroundworker bgw = this.bgWorker;
    this.bgWorker = null;
    if (disposing && bgw != null)
    {
      try
      {
      //TODO: release event handlers
      bgw.Dispose();
      }
      catch(Exception)
      {
        /* consumed disposal error */
      }
    }
  }
}

答案 1 :(得分:1)

我找到了解决我的问题的方法,使用C#中的BackgroundWorker类而不使用工具箱中的组件。在这种情况下,我需要两个单独的背景工作者:

using System.Threading;

public partial class MainWindow : Window
    {
        private BackgroundWorker bw1 = new BackgroundWorker();
        private BackgroundWorker bw2 = new BackgroundWorker();

        public MainWindow()
        {
            InitializeComponent();

            bw1.WorkerReportsProgress = true;
            bw1.DoWork += new DoWorkEventHandler(bw1_DoWork);
            bw1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw1_RunWorkerCompleted);
            bw1.ProgressChanged += new ProgressChangedEventHandler(bw1_ProgressChanged);

            bw2.WorkerReportsProgress = true;
            bw2.DoWork += new DoWorkEventHandler(bw2_DoWork2);
            bw2.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw2_RunWorkerCompleted);
            bw2.ProgressChanged += new ProgressChangedEventHandler(bw1_ProgressChanged);
        }


        private void bw1_DoWork(object sender, DoWorkEventArgs e)
        {
            StatsProcessor proc = new StatsProcessor();
            proc.CompareStats(listText1, listText2);    
        }

        private void bw2_DoWork2(object sender, DoWorkEventArgs e)
        {
            StatsParser parser = new StatsParser();
        }

        private void bw1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            progressBar2.IsIndeterminate = false;
            progressBar2.Value = 100;

            btnCompareStats.IsEnabled = true;

        }

        private void bw2_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            progressBar1.IsIndeterminate = false;
            progressBar1.Value = 100;

            btnFetchStats.IsEnabled = true;
        }

        private void bw1_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            this.progressBar2.Value = e.ProgressPercentage;
        }

        private void bw2_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            this.progressBar1.Value = e.ProgressPercentage;
        }

        private void btnCompare_Click(object sender, EventArgs e)
        {
            btnCompareStats.IsEnabled = false;

            StatsProcessor proc = new StatsProcessor();

            if (bw1.IsBusy != true)
                    {
                        progressBar2.IsIndeterminate = true;

                        // Start the asynchronous operation.
                        bw1.RunWorkerAsync();
                    }       

        }

        private void btnFetchStats_Click(object sender, RoutedEventArgs e)
        {
            btnFetchStats.IsEnabled = false;

            if (bw2.IsBusy != true)
                {
                       progressBar1.IsIndeterminate = true;

                       // Start the asynchronous operation.
                       bw2.RunWorkerAsync();
                }
        }
}

答案 2 :(得分:0)

我会尝试重置工具箱项目。然后使用“添加项目”对话框放回您需要的内容。