// show context menu when user presses the right button
        private void _flex_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                // hide current note, if any
                if (_note != null)
                {
                    _note.HideNote();
                    _note = null;
                }

                // make sure user clicked a valid cell
                int row = _flex.MouseRow;
                int col = _flex.MouseCol;
                if (row >= _flex.Rows.Fixed && col >= _flex.Cols.Fixed)
                {
                    // select cell that was clicked
                    _flex.Select(row, col);

                    // update context menu
                    bool hasNote = GetNoteAtMouse() != null;
                    _mInsertNote.Visible = !hasNote;
                    _mEditNote.Visible   = hasNote;
                    _mDeleteNote.Visible = hasNote;

                    // show the menu
                    _menuActive = true;
                    _menu.Show(_flex, new Point(e.X, e.Y));
                    //Application.DoEvents();
                    _menuActive = false;
                }
            }
        }
示例#2
0
        private void CustomDataTableDialog_Load(object sender, EventArgs e)
        {
            DataTable dt = DepositoryReportConfiguration.GetReportConfig();

            if (dt != null)
            {
                FpSpread_Panel.Columns.Count = 4;
                FpSpread_Panel.ColumnHeader.Cells[0, 0].Text = "ID";
                FpSpread_Panel.ColumnHeader.Cells[0, 1].Text = "项目";
                FpSpread_Panel.ColumnHeader.Cells[0, 2].Text = "单位";
                FpSpread_Panel.ColumnHeader.Cells[0, 3].Text = "频率";

                FpSpread_Panel.Columns[0].Width = 80;
                FpSpread_Panel.Columns[1].Width = 200;
                FpSpread_Panel.Columns[2].Width = 100;
                FpSpread_Panel.Columns[3].Width = 100;
                FpSpread_Panel.Rows.Count       = dt.Rows.Count;
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    FpSpread_Panel.Cells[i, 0].Value = dt.Rows[i]["ID"].ToString();
                    FpSpread_Panel.Cells[i, 1].Value = dt.Rows[i]["TestName"].ToString();
                    FpSpread_Panel.Cells[i, 2].Value = dt.Rows[i]["UnitName"].ToString();
                    FpSpread_Panel.Cells[i, 3].Value = dt.Rows[i]["Frequency"].ToString();
                    FpSpread_Panel.Rows[i].Tag       = dt.Rows[i]["ModuleID"].ToString();
                    CellNote.SetNoteInformation(FpSpread_Panel.Cells[i, 0], dt.Rows[i]["ModuleName"].ToString());
                }
            }
        }
        private void _mInsertNote_Click(object sender, System.EventArgs e)
        {
            // create note
            CellNote note = new CellNote("Note: ");

            // attach note to cell
            CellRange rg = _flex.Selection;

            rg.UserData = note;
            _flex.Invalidate();

            // go edit the new note
            _mEditNote_Click(sender, e);
        }
        //------------------------------------------------------------------------------------------------------
        #region ** menu event handlers

        private void _mDeleteNote_Click(object sender, System.EventArgs e)
        {
            // get note
            CellRange rg   = _flex.Selection;
            CellNote  note = rg.UserData as CellNote;

            // clear note
            if (note != null)
            {
                rg.UserData = null;
                _flex.Invalidate();
            }

            // resume showing notes
            _menuActive = false;
        }
        private void _mEditNote_Click(object sender, System.EventArgs e)
        {
            // get note
            CellRange rg   = _flex.Selection;
            CellNote  note = rg.UserData as CellNote;

            // edit note
            if (note != null)
            {
                Rectangle r = _flex.GetCellRect(rg.r1, rg.c1);
                r = _flex.RectangleToScreen(r);
                note.EditNote(r);
            }

            // resume showing notes
            _menuActive = false;
        }
        //------------------------------------------------------------------------------------------------------
        #region ** grid event handlers

        // show/hide cell notes
        private void _flex_MouseHoverCell(object sender, System.EventArgs e)
        {
            // hide current note, if any
            if (_note != null)
            {
                _note.HideNote();
                _note = null;
            }

            // don't show note if the grid is not focused or if the context menu is active
            if (!_flex.Focused || _menuActive)
            {
                return;
            }

            // show new note, if any
            _note = GetNoteAtMouse();
            if (_note != null)
            {
                Rectangle r = _flex.GetCellRect(_flex.MouseRow, _flex.MouseCol);
                r = _flex.RectangleToScreen(r);
                _note.ShowNote(r);
            }
        }