Ejemplo n.º 1
0
        public Form1(string filepath)
        {
            InitializeComponent();
            //make sure the file path is not null before intializing the spreadsheet
            if (filepath != null)
            {
                spread    = new Spreadsheet(filepath, s => true, s => s.ToUpper(), "ps6");
                this.Text = filepath;
                fileName  = filepath;
                saved     = true;
            }

            //initializing the state of the spreadsheet by
            // setting the selection to the first cell
            spreadsheetPanel1.SetSelection(0, 0);

            // Setting the textbox for the name to A1
            CellName.Text = "A1";

            // Displaying the cells
            DisplayPanelOnOpen(spreadsheetPanel1);

            //Adding the displayControlsOnSelection as a listener to the event handler for the panel
            spreadsheetPanel1.SelectionChanged += DisplayControlsOnSelection;

            // adding the function pd_PrintPage to the event handler pd.PrintPage, so that pd_PrintPage will be called
            // when the event is triggered.
            pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);

            // Setting the cursor to the textbox for cell contents.
            CellContents.Select();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// users can still click-select cells
        /// </summary>
        /// <remarks>
        /// This is actually trickier than it seems. We need to update the
        /// cell value and cell content txt boxes, update col,row,
        /// and ensure that focus is passed to the panel.
        /// Deselecting should release(write) the edit box text to the cell
        /// </remarks>
        /// <param name="sender"></param>
        private void Panel_SelectionChanged(SpreadsheetPanel sender)
        {
            Panel.GetSelection(out col, out row);


            CellNameBox.Text = this.ColRow_To_string(col, row);

            CellVal.Text = this.PrintableValue(sheetModel.GetCellValue(CellNameBox.Text));

            string To_cell_content_box;

            Panel.GetValue(col, row, out To_cell_content_box);
            CellContents.Text = To_cell_content_box;
            CellContents.Select(0, CellContents.Text.Length);



            this.Panel.Select();
            PanelFocus = true;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// I'm using this event to handle arrow keys. probably bad practice...
        /// oh well
        /// </summary>
        /// <param name="msg">I don't know what this does</param>
        /// <param name="keyData">Data about the keypress</param>
        /// <returns>a boolean...for obvious reasons...</returns>
        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (PanelFocus)
            {
                switch (keyData)
                {
                case Keys.Down:
                    Panel.SetSelection(col, ++row);
                    this.Panel_SelectionChanged(Panel);
                    break;

                case Keys.Up:
                    Panel.SetSelection(col, --row);
                    this.Panel_SelectionChanged(Panel);
                    break;

                case Keys.Left:
                    Panel.SetSelection(--col, row);
                    this.Panel_SelectionChanged(Panel);
                    break;

                case Keys.Right:
                    Panel.SetSelection(++col, row);
                    this.Panel_SelectionChanged(Panel);
                    break;

                default:
                    PanelFocus         = false;
                    CellContents.Text += new string((char)keyData, 1);
                    CellContents.Select(CellContents.Text.Length, 0);
                    //Panel.SetValue(col, row, CellContents.Text);
                    break;
                }
                this.CellContents.Select();
                return(true);
            }
            return(base.ProcessCmdKey(ref msg, keyData));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a file dialog that allows an existing file to be opened in the same window
        /// It will clear the contents of the existing window, and populate the window with the contents
        /// of the spreadsheet to be opened.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
        {
            try
            {
                // getting the filename from the file dialog
                string filePath = openFileDialog1.FileName;

                // emptying the spreadsheet
                spreadsheetPanel1.Clear();

                //creating a new spreadsheet from the specified file path
                spread = new Spreadsheet(filePath, s => true, s => s.ToUpper(), "ps6");

                this.Text = filePath;

                // updating the name of the spreadsheet window
                fileName = filePath;
                saved    = true;

                // setting the displays of the input boxes at the top
                DisplayControlsOnSelection(spreadsheetPanel1);

                // setting the display of the panels
                DisplayPanelOnOpen(spreadsheetPanel1);

                // adding the DisplayControlsOnSelection to event handler for the spreadsheet panel
                spreadsheetPanel1.SelectionChanged += DisplayControlsOnSelection;

                // setting the cursor to the CellContents input box
                CellContents.Select();
            }
            catch
            {
                MessageBox.Show("There was an error opening the file.  Please make sure that the filepath is correct, and that the file is a valid spreadsheet file.");
            }
        }