/// <summary> /// 历史Cookie按钮点击事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonHistoryCookies_Click(object sender, EventArgs e) { GlobalContext.RereadConfig(); this.contextMenuStrip1.Items.Clear(); //动态添加菜单 if (GlobalContext.HistoryCookies.Count < 1) { var menu = new ToolStripMenuItem(); menu.Text = "无"; this.contextMenuStrip1.Items.Add(menu); } else { foreach (var cookieInfo in GlobalContext.HistoryCookies) { var menuItem = new ToolStripMenuItem(); menuItem.Text = cookieInfo.Name;//Cookie名称 menuItem.Tag = cookieInfo; menuItem.Click += (s, ea) => { var info = (s as ToolStripMenuItem).Tag as CookieInfo; this.textBoxCookie.Text = info.Cookie; this.CookieString = info.Cookie; this.CertPath = info.CertPath; }; this.contextMenuStrip1.Items.Add(menuItem); } } //显示菜单 Point menuClientPoint = new Point(this.buttonHistoryCookies.Left, this.buttonHistoryCookies.Bottom); //菜单显示在按钮的正下方 Point menuScreenPoint = this.PointToScreen(menuClientPoint); //将控件的客户区域坐标转换为屏幕坐标 this.contextMenuStrip1.Show(menuScreenPoint); }