Пример #1
0
 private void MyToolStripDropDown_Opening(object sender, CancelEventArgs e)
 {
     try
     {
         myDropDownStatus = DropDownStatus.Opened;
         DropDownOpened   = true;
         if (myToolStripDropDown != null)
         {
             //Win32API.OutputDebugStringA(this.pnlTopParent.Width.ToString() );
             //myToolStripDropDown.Width = this.pnlTopParent.Width;
         }
         if (DropDownOpening != null)
         {
             DropDownOpening(this, e);
         }
     }
     catch (Exception ex)
     {
     }
     //throw new NotImplementedException();
 }
Пример #2
0
        private void MyToolStripDropDown_Closing(object sender, ToolStripDropDownClosingEventArgs e)
        {
            try
            {
                myDropDownStatus     = DropDownStatus.Closing;
                pboxArrow.Enabled    = true;
                DropDownOpened       = false;
                this.pboxArrow.Image = Properties.Resources.bArrow;
                //判断当前选择的项
                inputurl = "";
            }
            catch (Exception ex)
            {
            }
            //如果弹出了下拉列表框没有选择一项,则直接返回
            if (!bolDropDownMouseDown)
            {
                //return;
            }
            //选择了项,为下一次判断初始化为false
            bolDropDownMouseDown = false;

            try
            {
                //判断当前选择的项
                foreach (myToolStripButton titem in myToolStripDropDown.Items)
                {
                    //当前项,鼠标悬停,并不是真正意义上的点击选中
                    //Win32API.OutputDebugStringA(string.Format("所在项的 Pressed 为:{0}", titem.Pressed));
                    if (titem.Pressed)
                    {
                        inputurl = titem.Text;
                        if (!inputurl.Equals(ClearTips))//"清空地址栏下拉列表"
                        {
                            titem.IsSelected = true;
                            PressedItem      = titem;
                            //触发选择了某项事件
                            if (SelectionChanged != null)
                            {
                                SelectionChanged(this, e);
                            }
                        }
                        else
                        {
                            titem.IsSelected = false;
                        }
                    }
                    else
                    {
                        titem.IsSelected = false;
                    }
                    //Win32API.OutputDebugStringA(string.Format("所在项的IsSelected为:{0}", titem.IsSelected));
                }
                //重新遍历一遍myToolStripDropDown.Items,设置当前地址为选定项
                foreach (myToolStripButton titem in myToolStripDropDown.Items)
                {
                    if (titem == PressedItem)
                    {
                        titem.IsSelected = true;
                    }
                    else
                    {
                        titem.IsSelected = false;
                    }
                }
                myToolStripDropDown.Update();
                if ((string.IsNullOrEmpty(inputurl) || inputurl.Length <= 0))
                {
                    return;
                }
                else if (inputurl.Equals(ClearTips)) //"清空地址栏下拉列表"
                {
                    //Win32API.OutputDebugStringA(string.Format("在 myToolStripDropDown.Items中包含了:{0}个项目.", myToolStripDropDown.Items.Count ));
                    int iloopcount = myToolStripDropDown.Items.Count - 1;
                    for (int i = iloopcount; i >= 0; i--)
                    {
                        myToolStripButton item = myToolStripDropDown.Items[i] as myToolStripButton;

                        if (!item.Text.Equals(ClearTips))//"清空地址栏下拉列表"
                        {
                            myToolStripDropDown.Items.Remove(item);
                            //列表中删除该项
                            _items.Remove(item.Text);
                        }
                    }
                    myToolStripDropDown.Update();
                }
                else
                {
                    this.chboxAddress.Text = inputurl;
                    inputurl = "";
                }
                //this.cboxChildbox.DroppedDown = true;
            }
            catch (Exception ex)
            {
                pboxArrow.Enabled = true;
            }
            //触发事件
            try
            {
                if (DropDownClosed != null)
                {
                    DropDownClosed(this, e);
                }
            }
            catch (Exception ex)
            {
            }
            //throw new NotImplementedException();
        }