コード例 #1
0
 // 将选中的行数赋值给状态栏
 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;
         });
     }
 }
コード例 #2
0
 // 将选中字符数赋值给状态栏
 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();
         });
     }
 }
コード例 #3
0
 // 将总行数与总字符数赋值给状态栏
 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();
         });
     }
 }
コード例 #4
0
        /// <summary>
        /// 设置导出按钮
        /// </summary>
        private void setExportCombox()
        {
            // 实例化导出下拉框
            ComboBox comboBox = new ExportComBox(new ExportComBoxValEnum[] { ExportComBoxValEnum.EXPORT_JAVA_VAL });

            // 绑定点击事件
            comboBox.SelectedIndexChanged += (object sender, EventArgs e) => {
                ComboBox            box = (ComboBox)sender;
                ExportComBoxValEnum val = ExportComBox.stringToEnum(box.SelectedValue.ToString());
                switch (val)
                {
                case ExportComBoxValEnum.EXPORT_NEW_PAGE_VAL:
                    DataGridViewUtilMet.exportNewPage(redrawDataTable, excNoHaveTabs);
                    break;

                case ExportComBoxValEnum.EXPORT_THIS_PAGE_VAL:
                    DataGridViewUtilMet.exportThisPage(redrawDataTable, excNoHaveTabs);
                    break;

                case ExportComBoxValEnum.EXPORT_NOTEBOOK_VAL:
                    DataGridViewUtilMet.exportNotepad(redrawDataTable, excNoHaveTabs);
                    break;

                case ExportComBoxValEnum.EXPORT_EXCEL_VAL:
                    MessageBox.Show("该功能尚未完成");
                    // DataGridViewUtilMet.exportExcel(mainDataGridView, excNoHaveTabs);
                    break;
                }
            };
            // 加入到容器中
            表格内容_label.Location = new Point(表格内容_label.Location.X, (操作区容器.Height - 表格内容_label.Height) / 2 + 4);
            comboBox.Location   = new Point(表格内容_label.Right + 5, (操作区容器.Height - comboBox.Height) / 2 + 2);
            操作区容器.Controls.Add(comboBox);
            comboBox.BringToFront();
        }
コード例 #5
0
        /// <summary>
        /// 右键菜单鼠标点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void rightStripMenuItem_MouseDown(object sender, MouseEventArgs e)
        {
            ToolStripMenuItem item = (ToolStripMenuItem)sender;

            if (制全部Item.Equals(item))
            {
                Clipboard.SetDataObject(DataGridViewUtilMet.getDatatabelSelText(gridView, true), true);
            }
            if (制选中Item.Equals(item))
            {
                Clipboard.SetDataObject(DataGridViewUtilMet.getDatatabelSelText(gridView, false), true);
            }
            if (导出到记事本Item.Equals(item))
            {
                DataGridViewUtilMet.exportNotepad(gridView, true);
            }
            if (导出到Excel_Item.Equals(item))
            {
                DataGridViewUtilMet.exportExcel(gridView, true);
            }

            if (中此列Item.Equals(item))
            {
                if (gridView != null)
                {
                    DataGridViewSelectedCellCollection selCells = gridView.SelectedCells;
                    foreach (DataGridViewCell cell in selCells)
                    {
                        DataGridViewUtilMet.selectAllCellBySingle(gridView, cell.ColumnIndex, -1, true, false);
                    }
                }
            }
            if (中此行Item.Equals(item))
            {
                if (gridView != null)
                {
                    DataGridViewSelectedCellCollection selCells = gridView.SelectedCells;
                    foreach (DataGridViewCell cell in selCells)
                    {
                        DataGridViewUtilMet.selectAllCellBySingle(gridView, -1, cell.RowIndex, true, false);
                    }
                }
            }
            if (步选中单元格_该列Item.Equals(item))
            {
                DataGridViewUtilMet.cellsDataCopyToRowOrCol(gridView, 1);
            }
            if (步选中单元格_该行Item.Equals(item))
            {
                DataGridViewUtilMet.cellsDataCopyToRowOrCol(gridView, 0);
            }
            if (步选中单元格_行和列Item.Equals(item))
            {
                DataGridViewUtilMet.cellsDataCopyToRowOrCol(gridView, 2);
            }
        }
コード例 #6
0
 // 单元格鼠标按下事件
 protected override void OnCellMouseDown(DataGridViewCellMouseEventArgs e)
 {
     MouseDownButton      = e.Button;
     MouseDownColumnIndex = e.ColumnIndex;
     MouseDownRowIndex    = e.RowIndex;
     // 当要调整列宽或行高时不选中行
     if (!Cursor.Equals(Cursors.SizeWE) && !Cursor.Equals(Cursors.SizeNS) &&
         e.Button.Equals(MouseButtons.Left))
     {
         // 全选该列或行
         DataGridViewUtilMet.selectAllCellBySingle(this, e.ColumnIndex, e.RowIndex, true, true);
     }
     base.OnCellMouseDown(e);
 }
コード例 #7
0
 // 键盘按下事件
 private void MyKeyDown()
 {
     // ctrl+ c
     if (IsKeysCtrl && Keys.C.Equals(KeysDown))
     {
         DataGridViewUtilMet.copySelectCellText(this);
     }
     // ctrl+ v
     if (IsKeysCtrl && Keys.V.Equals(KeysDown))
     {
         DataGridViewUtilMet.pasteTextToSelCell(this);
     }
     // del
     if (Keys.Delete.Equals(KeysDown))
     {
         DataGridViewUtilMet.delSelectCellText(this);
     }
 }
コード例 #8
0
 // 将选中列数赋值给状态栏
 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();
         });
     }
 }