private ShengAddressBarDropDown GetButtonDropDown(IShengAddressNode addressNode) { ShengAddressBarDropDown dropDown = new ShengAddressBarDropDown(); if (this.DropDownRenderer != null) { dropDown.Renderer = this.DropDownRenderer; } dropDown.LayoutStyle = ToolStripLayoutStyle.Table; dropDown.MaximumSize = new Size(1000, 400); dropDown.Opening += new CancelEventHandler(DropDown_Opening); /* * This is the primary bottleneck for this app, creating all the necessary drop-down menu items. * * To optimize performance of this control, this is the main area that needs tuning. */ IShengAddressNode curNode = null; for (int i = 0; i < addressNode.Children.Length; i++) { curNode = (IShengAddressNode)addressNode.Children.GetValue(i); ShengAddressBarDropDownItem tsb = null; tsb = new ShengAddressBarDropDownItem(curNode.DisplayName, curNode.Icon, NodeButtonClicked); tsb.AddressNode = curNode; tsb.Overflow = ToolStripItemOverflow.AsNeeded; dropDown.Items.Add(tsb); //THIS IS THE BIGGEST BOTTLENECK. LOTS OF TIME SPENT IN/CALLING THIS METHOD! } addressNode.DropDownMenu = dropDown; dropDown.LayoutStyle = ToolStripLayoutStyle.Table; dropDown.MaximumSize = new Size(1000, 400); dropDown.AddressNode = addressNode; //不起作用 dropDown.MouseWheel += new MouseEventHandler(ScrollDropDownMenu); dropDown.MouseEnter += new EventHandler(GiveToolStripDropDownMenuFocus); return(dropDown); }
private void DropDown_Opening(object sender, CancelEventArgs e) { ShengAddressBarDropDown dropDown = sender as ShengAddressBarDropDown; //dropDown.Left = dropDown.Left - 20; #region 把当前选中项加粗 IShengAddressNode nextAddressNode = null; for (int i = 0; i < _buttonList.Count; i++) { //如果是当前点击的向下箭头 if (_buttonList[i].DropDownButton != null && _buttonList[i].DropDownButton.DropDown == dropDown) { //拿出当前点的地址栏按钮向下箭头的下一个地址栏项目 //如果为空,则表示当前点的是最右边的了,那就不去匹配了,也没得匹配 if ((i + 1) < _buttonList.Count) { nextAddressNode = _buttonList[i + 1].AddressNode; break; } } } if (nextAddressNode != null) { foreach (ShengAddressBarDropDownItem item in dropDown.Items) { //在使用SetAddress逆向初始化节点时 //会出现item.AddressNode 和 nextAddressNode不是一个对象的情况 //所以需要UniqueID来判断 if (item.AddressNode.UniqueID.Equals(nextAddressNode.UniqueID)) { item.Font = new Font(item.Font, this._selectedStyle); break; } } } #endregion }