// 将选中字符数赋值给状态栏
 private void setSelectChars(Control con)
 {
     if (con == null)
     {
         MessageBox.Show("无法获取控件");
     }
     if (con is TextBox)  // 获取文本框
     {
         TextBox t = (TextBox)con;
         // 开辟新线程执行方法
         ControlsUtils.AsynchronousMethod(this, 1, delegate {
             ToolStripLabel lable1 = (ToolStripLabel)this.Items[StrutsStripDataLib.ItemName.中字符数];
             string tag1           = lable1.Tag != null?lable1.Tag.ToString() + ":":"";
             // 给状态栏赋值
             lable1.Text = tag1 + t.SelectionLength.ToString();
         });
     }
     else if (con is DataGridView)   // 表格
     {
         DataGridView g = (DataGridView)con;
         // 开辟新线程执行方法
         ControlsUtils.AsynchronousMethod(this, 1, delegate {
             ToolStripLabel lable1 = (ToolStripLabel)this.Items[StrutsStripDataLib.ItemName.中字符数];
             string tag1           = lable1.Tag != null?lable1.Tag.ToString() + ":":"";
             // 给状态栏赋值
             lable1.Text = tag1 + DataGridViewUtilMet.getDatatabelSelText(g, false)
                           .Replace("\t", "").Replace(Environment.NewLine, "").Length.ToString();
         });
     }
 }
Esempio n. 2
0
        /// <summary>
        /// 将文本框打开的文件路径显示到文本框的父容器下目录下
        /// </summary>
        private void setParentTextByFileName()
        {
            TextBox t = this;
            // 获取文本框的父容器
            Control con = t.Parent;

            // 判断父容器是否为TabPage
            if (con.GetType().Equals(typeof(TabPage)))
            {
                ControlsUtils.AsynchronousMethod(t, 300, delegate {
                    // 判断Tag中是否存在保存路径
                    if (TextBoxUtils.GetTextTagToMap(t).ContainsKey(TextBoxTagKey.SAVE_FILE_PATH))
                    {
                        string filepath  = TextBoxUtils.GetTextTagToMap(t)[TextBoxTagKey.SAVE_FILE_PATH].ToString();
                        TabPage page     = (TabPage)t.Parent;
                        string[] pathArr = FileUtils.GetPathArr(filepath);
                        page.ResetText();

                        // 设置标签文本
                        page.Text = pathArr[1];
                        // 设置提示文本
                        page.ToolTipText = filepath;
                    }
                });
            }
        }
 // 将总行数与总字符数赋值给状态栏
 private void setRowChars(Control con)
 {
     if (con == null)
     {
         MessageBox.Show("无法获取控件");
     }
     if (con is TextBox)  // 获取文本框
     {
         TextBox t = (TextBox)con;
         // 开辟新线程执行方法
         ControlsUtils.AsynchronousMethod(this, 1, delegate {
             ToolStripLabel lable1 = (ToolStripLabel)this.Items[StrutsStripDataLib.ItemName.总行数];
             ToolStripLabel lable2 = (ToolStripLabel)this.Items[StrutsStripDataLib.ItemName.总字符数];
             string tag1           = lable1.Tag != null?lable1.Tag.ToString() + ":":"";
             string tag2           = lable2.Tag != null?lable2.Tag.ToString() + ":":"";
             lable1.Text           = tag1 + TextBoxUtils.GetTextBoxTotalRow(t).ToString();
             lable2.Text           = tag2 + TextBoxUtils.GetTextBoxChars(t, false).ToString();
         });
     }
     else if (con is DataGridView)   // 表格
     {
         DataGridView g = (DataGridView)con;
         // 开辟新线程执行方法
         ControlsUtils.AsynchronousMethod(this, 1, delegate {
             ToolStripLabel lable1 = (ToolStripLabel)this.Items[StrutsStripDataLib.ItemName.总行数];
             ToolStripLabel lable2 = (ToolStripLabel)this.Items[StrutsStripDataLib.ItemName.总字符数];
             string tag1           = lable1.Tag != null?lable1.Tag.ToString() + ":":"";
             string tag2           = lable2.Tag != null?lable2.Tag.ToString() + ":":"";
             lable1.Text           = tag1 + g.RowCount.ToString();
             lable2.Text           = tag2 + DataGridViewUtilMet.getDatatabelSelText(g, true)
                                     .Replace("\t", "").Replace(Environment.NewLine, "").Length.ToString();
         });
     }
 }
 // 设置状态栏的编码
 private object setToolSatrtEcoding(Control con)
 {
     if (con == null)
     {
         MessageBox.Show("无法获取控件");
     }
     // 获取文本框
     if (con is TextBox)
     {
         TextBox t = (TextBox)con;
         // 开辟新线程执行方法
         ControlsUtils.AsynchronousMethod(t, 300, delegate {
             Dictionary <string, object> tag = TextBoxUtils.GetTextTagToMap(t);
             Encoding ecoding = TextBoxDataLibcs.TEXTBOX_ECODING_DEF;
             // 获取文本框中Tag中存的编码
             if (tag.ContainsKey(TextBoxTagKey.TEXTBOX_TAG_KEY_ECODING))
             {
                 ecoding = (Encoding)TextBoxUtils.GetTextTagToMap(t)[TextBoxTagKey.TEXTBOX_TAG_KEY_ECODING];
             }
             // 全局单例控件工厂
             Dictionary <string, Control> single = ControlCacheFactory.getSingletonCache();
             if (single.ContainsKey(EnumUtils.GetDescription(DefaultNameEnum.TOOL_START)))
             {
                 // 状态栏
                 ToolStrip toolStrip = (ToolStrip)single[EnumUtils.GetDescription(DefaultNameEnum.TOOL_START)];
                 // 获取编码Item
                 ToolStripItem labEcoding = toolStrip.Items[StrutsStripDataLib.ItemName.编码];
                 labEcoding.Text          = ecoding.BodyName.ToUpper();
             }
         });
     }
     return(null);
 }
 // 将选中的行数赋值给状态栏
 private void setSelectRow(Control con)
 {
     if (con == null)
     {
         MessageBox.Show("无法获取控件");
     }
     if (con is TextBox)  // 获取文本框
     {
         TextBox t = (TextBox)con;
         // 开辟新线程执行方法
         ControlsUtils.AsynchronousMethod(this, 1, delegate {
             ToolStripLabel lable1 = (ToolStripLabel)this.Items[StrutsStripDataLib.ItemName.中行];
             int val = 0;
             if (t.SelectedText.Length > 0)
             {
                 val = StringUtils.SplitStrToArray(t.SelectedText,
                                                   new string[] { Environment.NewLine }, true, false).Length;
             }
             // 将选中行赋值给label
             lable1.Text = lable1.Text.Split(':')[0] + ":" + val;
         });
     }
     else if (con is DataGridView)   // 表格
     {
         DataGridView g = (DataGridView)con;
         // 开辟新线程执行方法
         ControlsUtils.AsynchronousMethod(this, 1, delegate {
             ToolStripLabel lable1 = (ToolStripLabel)this.Items[StrutsStripDataLib.ItemName.中行];
             int val = DataGridViewUtilMet.getSelCellRowsColns(g)[0].Length;
             // 将选中行赋值给label
             lable1.Text = lable1.Text.Split(':')[0] + ":" + val;
         });
     }
 }
Esempio n. 6
0
        /// <summary>
        /// 将文本框打开的文件路径显示到文本框的父容器下目录下
        /// </summary>
        /// <param name="t"></param>
        public static object setParentTextByFileName(Dictionary <Type, object> data)
        {
            TextBox t = (TextBox)data[typeof(TextBox)];
            // 获取文本框的父容器
            Control con = t.Parent;

            // 判断父容器是否为TabPage
            if (con.GetType().Equals(typeof(TabPage)))
            {
                ControlsUtils.AsynchronousMethod(t, 300, delegate {
                    // 判断Tag中是否存在保存路径
                    if (TextBoxUtils.GetTextTagToMap(t).ContainsKey(TextBoxTagKey.SAVE_FILE_PATH))
                    {
                        string filepath  = TextBoxUtils.GetTextTagToMap(t)[TextBoxTagKey.SAVE_FILE_PATH].ToString();
                        TabPage page     = (TabPage)t.Parent;
                        string[] pathArr = FileUtils.GetPathArr(filepath);
                        page.ResetText();

                        // 设置标签文本
                        page.Text = pathArr[1];
                        // 设置提示文本
                        page.ToolTipText = filepath;
                    }
                });
            }
            return(null);
        }
 // 刷新控件只读状态
 private object refreshTextReadOnly(Control con)
 {
     if (con == null)
     {
         MessageBox.Show("无法获取控件");
     }
     if (con is TextBox)  // 获取文本框
     {
         TextBox t = (TextBox)con;
         // 开辟新线程执行方法
         ControlsUtils.AsynchronousMethod(this, 1, delegate {
             // 获取只读lable
             ToolStripLabel lable1 = (ToolStripLabel)this.Items[StrutsStripDataLib.ItemName.只读状态];
             bool only             = t.ReadOnly;
             string tag1           = lable1.Tag != null? lable1.Tag.ToString() + ":":"";
             // 给状态栏赋值
             lable1.Text = tag1 + (only?"是" : "否");
         });
     }
     else if (con is DataGridView)   // 表格
     {
         DataGridView g = (DataGridView)con;
         // 开辟新线程执行方法
         ControlsUtils.AsynchronousMethod(this, 1, delegate {
             // 获取只读lable
             ToolStripLabel lable1 = (ToolStripLabel)this.Items[StrutsStripDataLib.ItemName.只读状态];
             bool only             = g.ReadOnly;
             string tag1           = lable1.Tag != null? lable1.Tag.ToString() + ":":"";
             // 给状态栏赋值
             lable1.Text = tag1 + (only?"是" : "否");
         });
     }
     return(null);
 }
 // 调整大小事件
 protected override void OnResize(EventArgs e)
 {
     ControlsUtils.AsynchronousMethod(this, 0, delegate {
         doIsAddPageSizeMode();
         doIsAddPageButLocation(addPageBut);
     });
     base.OnResize(e);
 }
 /// <summary>
 /// 表格默认配置
 /// </summary>
 /// <param name="cellHeight">单元格高</param>
 /// <param name="colHeadersHeight">列标题高</param>
 private void initDatatableDefConfig()
 {
     ControlsUtils.AsynchronousMethod(this, 1, delegate {
         // 设置单元格默认样式
         setDefaultCellStyle();
         // 设置列标题默认样式
         setDefaultColumnHeadStyle();
         // 设置行标题默认样式
         setDefaultRowHeadStyle();
     });
     // 设置基本样式
     setDataTableStyle();
     // 绑定右键菜单并使用自定义的样式
     DataGridViewRightMenu.bindingDataGridView(this);
 }
Esempio n. 10
0
 // 鼠标按钮按下选中文本
 private void mouseDownSelectText()
 {
     if (MouseButtons.Left.Equals(MouseDownButton)) // 点击的左键
     {
         Point p = MouseDownLocation;
         if (p.X < 0)
         {
             p.X = 0;
         }
         if (p.Y < 0)
         {
             p.Y = 0;
         }
         int mouseIndex = this.GetCharIndexFromPosition(p);
         int selIndex   = this.SelectionStart;
         if (KeysDown.Equals(Keys.ShiftKey)) // 按下了shift
         {
             if (mouseIndex < selIndex)
             {
                 this.SelectionStart = mouseIndex;
             }
             else
             {
                 this.SelectionStart = SelectionStart;
             }
             this.SelectionLength = Math.Abs(mouseIndex - selIndex);
         }
         else
         {
             if (isMouseEnterSelectText(p) /*|| SelectionLength == 0*/)
             {
                 ControlsUtils.AsynchronousMethod(this, 120, new EventHandler((object sender1, EventArgs e1) => {
                     if (!Cursor.Equals(selectTextDragCur) && MouseDownButton.Equals(MouseButtons.None))
                     {
                         SelectionLength = 0;
                         SelectionStart  = mouseIndex;
                     }
                 }));
             }
             else
             {
                 SelectionLength = 0;
                 SelectionStart  = mouseIndex;
             }
         }
     }
 }
 // 将大小写状态赋值给状态栏
 private void setCaseKey(Control con)
 {
     // 获取文本框
     // 开辟新线程执行方法
     ControlsUtils.AsynchronousMethod(this, 1, delegate {
         ToolStripLabel lable = (ToolStripLabel)this.Items[StrutsStripDataLib.ItemName.大小写状态];
         // 判断当前为大写
         if (WindowsApiUtils.GetCapitalState())
         {
             lable.Text = "大写";
         }
         else
         {
             lable.Text = "小写";
         }
     });
 }
        // 控件移除事件
        protected override void OnControlRemoved(ControlEventArgs e)
        {
            if (e.Control is TabPage)
            {
                TabPage ppp = (TabPage)e.Control;
                // 确定移除标签后的显示模式
                delPageIsPageMode(ppp);
                ControlsUtils.AsynchronousMethod(this, 0, delegate {
                    // 确定显示模式
                    doIsAddPageSizeMode();
                    // 确定添加按钮的位置
                    doIsAddPageButLocation(addPageBut);
                });
            }

            base.OnControlRemoved(e);
        }
 // 将选中的项目数赋值给状态栏
 private void setSelectItem(Control con)
 {
     if (con == null)
     {
         MessageBox.Show("无法获取控件");
     }
     if (con is DataGridView)  // 表格
     {
         DataGridView g = (DataGridView)con;
         // 开辟新线程执行方法
         ControlsUtils.AsynchronousMethod(this, 1, delegate {
             ToolStripLabel lable1 = (ToolStripLabel)this.Items[StrutsStripDataLib.ItemName.中元素];
             string tag1           = lable1.Tag != null?lable1.Tag.ToString() + ":":"";
             // 给状态栏赋值
             lable1.Text = tag1 + g.SelectedCells.Count.ToString();
         });
     }
 }
 // 将选中列数赋值给状态栏
 private void setSelectColumn(Control con)
 {
     if (con == null)
     {
         MessageBox.Show("无法获取控件");
     }
     if (con is DataGridView)  // 表格
     {
         DataGridView g = (DataGridView)con;
         // 开辟新线程执行方法
         ControlsUtils.AsynchronousMethod(this, 1, delegate {
             ToolStripLabel lable1 = (ToolStripLabel)this.Items[StrutsStripDataLib.ItemName.中列];
             string tag1           = lable1.Tag != null?lable1.Tag.ToString() + ":":"";
             int selColum          = DataGridViewUtilMet.getSelCellRowsColns(g)[1].Length;
             // 给状态栏赋值
             lable1.Text = tag1 + selColum.ToString();
         });
     }
 }
        // 控件添加事件
        protected override void OnControlAdded(ControlEventArgs e)
        {
            Control con = e.Control;

            if (con.Location.Y < 2)
            {
                con.Location = new Point(con.Location.X, con.Location.Y + 2);
                con.Size     = new Size(con.Width, con.Height - 2);
            }
            if (IsAssociationStatusBar)
            {
                ControlsUtils.AsynchronousMethod(this, 1, new EventHandler((object sender2, EventArgs e2) => {
                    statusBarAssociation();
                }));
            }
            ;
            setPageDispLayout();
            base.OnControlAdded(e);
        }
 // 将当前的行列数赋值给状态栏
 private void setRowColumn(Control con)
 {
     if (con == null)
     {
         MessageBox.Show("无法获取控件");
     }
     if (con is TextBox)  // 获取文本框
     {
         TextBox t = (TextBox)con;
         // 开辟新线程执行方法
         ControlsUtils.AsynchronousMethod(this, 1, delegate {
             ToolStripLabel lable1 = (ToolStripLabel)this.Items[StrutsStripDataLib.ItemName.行列数];
             int[] val             = TextBoxUtils.GetTextBoxRowColumn(t);
             string tag1           = lable1.Tag != null?lable1.Tag.ToString():"";
             if (val != null)
             {
                 //将行与列赋值给label
                 lable1.Text = tag1.Replace("{1}", val[0].ToString())
                               .Replace("{2}", val[1].ToString());
             }
         });
     }
     else if (con is DataGridView)   // 表格
     {
         DataGridView g = (DataGridView)con;
         // 开辟新线程执行方法
         ControlsUtils.AsynchronousMethod(this, 1, delegate {
             ToolStripLabel lable1 = (ToolStripLabel)this.Items[StrutsStripDataLib.ItemName.行列数];
             int[] val             = new int[] {
                 g.SelectedCells.Count > 0? g.SelectedCells[0].RowIndex + 1: 0,
                 g.SelectedCells.Count > 0? g.SelectedCells[0].ColumnIndex + 1: 0
             };
             string tag1 = lable1.Tag != null?lable1.Tag.ToString():"";
             if (val != null)
             {
                 //将行与列赋值给label
                 lable1.Text = tag1.Replace("{1}", val[0].ToString())
                               .Replace("{2}", val[1].ToString());
             }
         });
     }
 }
Esempio n. 17
0
 // 开启或关闭鼠标选中文本的拖放
 private void diIsSelectTextDrag()
 {
     // 判断是否要启用拖放操作
     ControlsUtils.AsynchronousMethod(this, 100, new EventHandler((object sender1, EventArgs e1) => {
         Point p = MouseDownLocation;
         if (p.X < 0)
         {
             p.X = 0;
         }
         if (p.Y < 0)
         {
             p.Y = 0;
         }
         if (MouseDownButton.Equals(MouseButtons.Left) && isMouseEnterSelectText(p))
         {
             Cursor = selectTextDragCur;
         }
         ;
     }));
 }
        // 状态栏的双击事件对应关系
        private Dictionary <string, Delegate> doubleClickEventBinding()
        {
            Dictionary <string, Delegate> toolBindingDic = new Dictionary <string, Delegate>();

            toolBindingDic.Add(StrutsStripDataLib.ItemName.总字符数, new methodDelegate((Control con) => {
                if (con == null)
                {
                    MessageBox.Show("无法获取控件");
                }
                // 获取控件
                if (con is TextBox)
                {
                    TextBox t = (TextBox)con;
                    CharsStatistics.openCharsStatistics(t);
                }
                return(null);
            }));
            toolBindingDic.Add(StrutsStripDataLib.ItemName.总行数, new methodDelegate((Control con) => {
                Form ff = UIComponentFactory.getSingleForm(DefaultNameEnum.ROW_GOTO_FORM, false);
                ff.ShowDialog();
                return(null);
            }));
            toolBindingDic.Add(StrutsStripDataLib.ItemName.行列数, new methodDelegate((Control con) => {
                if (con == null)
                {
                    MessageBox.Show("无法获取控件");
                }
                // 获取控件
                if (con is TextBox)
                {
                    TextBox t = (TextBox)con;
                    CharsStatistics.openCharsStatistics(t);
                }
                return(null);
            }));
            toolBindingDic.Add(StrutsStripDataLib.ItemName.中字符数, new methodDelegate((Control con) => {
                if (con == null)
                {
                    MessageBox.Show("无法获取控件");
                }
                // 获取控件
                if (con is TextBox)
                {
                    TextBox t = (TextBox)con;
                    CharsStatistics.openCharsStatistics(t);
                }
                return(null);
            }));
            toolBindingDic.Add(StrutsStripDataLib.ItemName.编码, new methodDelegate((Control con) => {
                Form ff = UIComponentFactory.getSingleForm(DefaultNameEnum.SET_CODING_FORM, false);
                ff.ShowDialog();
                return(null);
            }));
            toolBindingDic.Add(StrutsStripDataLib.ItemName.大小写状态, new methodDelegate((Control con) => {
                // 开辟新线程执行方法
                ControlsUtils.AsynchronousMethod(this, 1, delegate {
                    ToolStripLabel lable = (ToolStripLabel)this.Items[StrutsStripDataLib.ItemName.大小写状态];
                    byte[] bs            = new byte[256];
                    //判断当前大小写1为大写
                    WindowsApiUtils.GetKeyboardState(bs);
                    if (bs[0x14].Equals(1))  // 判断当前为大写
                    //设置为小写
                    {
                        WindowsApiUtils.SetCapitalState(false);
                        lable.Text = "小写";
                    }
                    else
                    {
                        WindowsApiUtils.SetCapitalState(true);
                        lable.Text = "大写";
                    }
                });
                return(null);
            }));
            toolBindingDic.Add(StrutsStripDataLib.ItemName.只读状态, new methodDelegate(setTextReadOnly));
            return(toolBindingDic);
        }
        /// <summary>
        /// 单元格选中后改变对应的行标题,列标题颜色
        /// </summary>
        /// <param name="colIndex">选中单元格列索引</param>
        /// <param name="rowIndex">选中单元格行索引</param>
        /// <param name="view">表格</param>
        /// <param name="back">背景色</param>
        /// <param name="fontC">前景色</param>
        public static void selectCallHeandColor(int colIndex, int rowIndex, DataGridView view, Color back, Color fontC)
        {
            // 默认列标题背景色
            Color colHeadBack = view.ColumnHeadersDefaultCellStyle.BackColor;
            // 默认列标题前景色
            Color colHeadColor = view.ColumnHeadersDefaultCellStyle.ForeColor;
            // 默认列标题字体
            Font colHeadFont = view.ColumnHeadersDefaultCellStyle.Font;

            // 默认行标题背景色
            Color rowHeadBack = view.RowHeadersDefaultCellStyle.BackColor;
            // 默认行标题前景色
            Color rowHeadColor = view.RowHeadersDefaultCellStyle.ForeColor;
            // 默认行标题字体
            Font rowHeadFont = view.RowHeadersDefaultCellStyle.Font;

            // 开辟新线程执行方法
            ControlsUtils.AsynchronousMethod(view, 1, new EventHandler(delegate {
                //获取该单元格
                DataGridViewCell cell = view.Rows[rowIndex].Cells[colIndex];
                // 判断该列索引不为-1
                if (colIndex != -1)
                {
                    // 改变列标题的样式
                    // 判断当前单元格是否选中
                    if (cell.Selected)
                    {
                        // 改变样式
                        DataGridViewCellStyle cellSty = view.RowsDefaultCellStyle;
                        // 设置选中列头和行头的样式
                        view.Columns[colIndex].HeaderCell.Style.BackColor = back;
                        view.Columns[colIndex].HeaderCell.Style.ForeColor = fontC;
                        // 文本加粗
                        view.Columns[colIndex].HeaderCell.Style.Font
                            = new Font(colHeadFont, FontStyle.Bold);
                    }
                    else
                    {
                        // 恢复默认
                        view.Columns[colIndex].HeaderCell.Style.BackColor = colHeadBack;
                        view.Columns[colIndex].HeaderCell.Style.ForeColor = colHeadColor;
                        view.Columns[colIndex].HeaderCell.Style.Font      = colHeadFont;
                    }
                }

                // 改变行标题的样式
                // 判断该行索引不为-1
                if (rowIndex != -1)
                {
                    if (cell.Selected)
                    {
                        // 单元格样式
                        DataGridViewCellStyle cellSty = view.RowsDefaultCellStyle;
                        // 设置选中列头和行头的样式
                        view.Rows[rowIndex].HeaderCell.Style.BackColor = back;
                        view.Rows[rowIndex].HeaderCell.Style.ForeColor = fontC;
                        // 文本加粗
                        view.Rows[rowIndex].HeaderCell.Style.Font
                            = new Font(colHeadFont, FontStyle.Bold);
                    }
                    else
                    {
                        view.Rows[rowIndex].HeaderCell.Style.BackColor = colHeadBack;
                        view.Rows[rowIndex].HeaderCell.Style.ForeColor = colHeadColor;
                        view.Rows[rowIndex].HeaderCell.Style.Font      = rowHeadFont;
                    }
                }
            }));
        }