C# 如何将System.ComponentModel.Container代码添加到form1?获得模糊度误差

C# 如何将System.ComponentModel.Container代码添加到form1?获得模糊度误差,c#,.net,winforms,C#,.net,Winforms,在表格1的顶部,我添加了: private System.ComponentModel.IContainer components; 然后,在我创建的私有方法中,我做到了: private void NotifyIconSettings() { this.components = new System.ComponentModel.Container(); } 但我在线路上遇到了错误:在this.components上 this.com

在表格1的顶部,我添加了:

private System.ComponentModel.IContainer components;
然后,在我创建的私有方法中,我做到了:

private void NotifyIconSettings()
        {
            this.components = new System.ComponentModel.Container();
        }
但我在线路上遇到了错误:在this.components上

this.components = new System.ComponentModel.Container();
错误1“Pop3_Emails.Form1.components”和“Pop3_Emails.Form1.components”之间存在歧义

我不想使用Pop3_Emails.Form1.components

this.components = new System.ComponentModel.Container();
更新

我现在尝试的是在form1构造函数中添加的:

contextMenu1.MenuItems.Add("&Open Application");
contextMenu1.MenuItems.Add("S&uspend Application");
contextMenu1.MenuItems.Add("E&xit");
notifyIcon1.Visible = true;
notifyIcon1.Text = "Right-click me!";
notifyIcon1.ContextMenu = contextMenu1;

现在右键单击托盘图标中的图标,我看到了菜单,但我现在如何添加单击事件并处理每个菜单项?我的意思是当我点击退出,程序就会退出。现在它什么都没用了。

你为什么要用它呢?我现在不需要你。我现在用我试过的方法编辑了我的问题。你应该改用ContextMenuStrip。它取代了ContextMenu版本。add参数之一用于事件处理程序,因此您必须事先为其编写方法。