statusStrip1 是拖放在界面上的.然后动态 的   在statusStrip1 任务栏上加了几个 ToolStripStatusLabel,现在 要根据事件移除掉.?怎么移除?
都获不到ToolStripStatusLabel,
提示错误:无法通过引用转换、装箱转换、取消装箱转换、包装转换或 Null 类型转换将类型“System.Windows.Forms.Control”转换为“System.Windows.Forms.ToolStripStatusLabel”

解决方案 »

  1.   

    很简单,System.Windows.Forms.ToolStripStatusLabel与System.Windows.Forms.Control之间不存在继承关系。
    System.Windows.Forms.ToolStripLabel
    System.Windows.Forms.ToolStripItem
    System.ComponentModel.Component
    System.Windows.Forms.IDropTarget
    System.Windows.Forms.ISupportOleDropSource
    System.Windows.Forms.Layout.IArrangedElement看到这种继承关系没有。
      

  2.   

    this.statusStrip1.Items.Remove(toolStripStatusLabel1);
      

  3.   

    toolStripStatusLabel1 是动态加的.
    所以获取不到toolStripStatusLabel .
    但是,知道要移除控件的ID.  
    有没有办法啊.
      

  4.   

    遍历
    但你总要有一个方法确定要删除的label,要么名字,要么文本。
    ToolStripItem removeItem;
    foreach(ToolStripItem c in this.statusStrip1.Items)
    {
        if(c.Text == "你指定的文本")
        {
            removeItem = c;
            break;
        }
    }
    if(removeItem != null) this.statusStrip1.Items.Remove(removeItem)'
      

  5.   

    谢谢大家的帮助.最终wangwenzhuang发了一个简明的示例,得以快速解决.谢谢