コード例 #1
0
        /// <summary>
        /// 菜单子选项的总绑定类,执行选项name对应的绑定类
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MenuItem_Click(object sender, EventArgs e)
        {
            try {
                ToolStripMenuItem tool = (ToolStripMenuItem)sender;
                //获取当前主Tab容器中的文本框
                TextBox t       = null;
                Control control = null;
                // 获得主tab容器
                Control tabCon = ControlCacheFactory.getSingletonCache(DefaultNameEnum.TAB_CONTENT);
                if (tabCon != null && tabCon is TabControl)
                {
                    TabControl tab = (TabControl)tabCon;
                    if (t == null)
                    {
                        control = ControlsUtils.GetControlByName(tab.SelectedTab.Controls, EnumUtils.GetDescription(DefaultNameEnum.TEXTBOX_NAME_DEF), true);
                        if (control != null && control is TextBox)
                        {
                            t = (TextBox)control;
                        }
                    }
                    if (t == null)
                    {
                        control = ControlsUtils.GetFocueControlByType(tab.SelectedTab.Controls);
                        if (control != null && control is TextBox)
                        {
                            t = (TextBox)control;
                        }
                    }
                }
                // 遍历对应关系字典
                foreach (KeyValuePair <string, Delegate> kvp in eventBinding())
                {
                    // 判断当前点击的选项名是否与关系字典中的选项名对应,对应则执行关系字典中的对应方法
                    if (kvp.Key.Equals(tool.Name))
                    {
                        // 判断当前控件是否有与其关联的句柄
                        if (topMenuStrip.IsHandleCreated)
                        {
                            Dictionary <Type, object> data = new Dictionary <Type, object>();
                            data.Add(typeof(TextBox), t);
                            data.Add(typeof(ToolStripMenuItem), tool);

                            topMenuStrip.Invoke(kvp.Value, new object[] { data });
                        }
                    }
                }
            }
            catch (Exception ex) {
                MessageBox.Show(ex.ToString());
            }
        }
コード例 #2
0
        // 状态栏的双击公用事件
        private void toolLabelDoubleClick(object sender, EventArgs e)
        {
            ToolStripLabel label      = (ToolStripLabel)sender;
            Delegate       myDelegate = null;

            doubleClickEventBinding().TryGetValue(label.Name, out myDelegate);
            if (myDelegate != null)
            {
                Dictionary <Type, object> data = new Dictionary <Type, object>();
                // 获取源控件中获取焦点的控件
                Control focusCon = ControlsUtils.GetFocueControlByType(SourceControlArr);
                this.Invoke(myDelegate, new object[] { focusCon });
            }
        }