添加Reference:
System.ServiceProcess.dll

解决方案 »

  1.   

    在右侧上部项目上点右键,添加->引用,在弹出的对话框中确认选择了.NET页,所以选择System.ServiceProcess。
      

  2.   

    先谢谢楼上的两位。不过我试了下还是不行反而引出了更多的错误错误 1 “System.Windows.Forms.Control”并不包含“DisplayName”的定义
    错误 2 “System.Windows.Forms.Control”并不包含“Status”的定义
    错误 3 当前上下文中不存在名称“ServiceControllerStatus”
    错误 4 当前上下文中不存在名称“RefreshList”
    错误 5 当前上下文中不存在名称“controller”
    错误 6 当前上下文中不存在名称“controller”
    错误 7 当前上下文中不存在名称“controller”
    错误 8 当前上下文中不存在名称“controller”
    错误 9 当前上下文中不存在名称“ServiceControllerStatus”
    错误 10 当前上下文中不存在名称“RefreshList”
    错误 11 当前上下文中不存在名称“controller”
    错误 12 当前上下文中不存在名称“controller”
    错误 13 当前上下文中不存在名称“controller”
    错误 14 当前上下文中不存在名称“controller”
    错误 15 当前上下文中不存在名称“ServiceControllerStatus”
    错误 16 当前上下文中不存在名称“RefreshList”
    错误 17 当前上下文中不存在名称“controller”
    错误 18 当前上下文中不存在名称“controller”
    错误 19 当前上下文中不存在名称“controller”
    错误 20 当前上下文中不存在名称“controller”
    错误 21 当前上下文中不存在名称“ServiceControllerStatus”
    错误 22 当前上下文中不存在名称“RefreshList”
    错误 23 当前上下文中不存在名称“controller”
      

  3.   

    private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
            {
                control = (System.ServiceProcess.ServiceController)
                listBox1.SelectedItem;
                textBox1.Text = Control.DisplayName;
                switch (Control.Status)
    注意注意,应该是 control.DisplayName 吧,下边的也是,小心 IntelliSense!
    如果用 Control.DisplayName,编译器会误以为你想调用 System.Windows.Forms.Control 类的静态方法 DisplayName,而非 System.ServiceProcess.ServiceController 类的某个实例的属性(control.DisplayName)。
      

  4.   

      问题总算解决了谢谢LaoBai_2006 !!! 也感谢lalac和Eric_zdhz的热心帮助总之谢谢大家^_^