Beispiel #1
0
 /// <summary>
 /// Returns the one SheetFormAppContext.
 /// </summary>
 public static SheetFormAppContext getAppContext()
 {
     if (appContext == null)
     {
         appContext = new SheetFormAppContext();
     }
     return(appContext);
 }
        /// <summary>
        /// Deals with new menu
        /// </summary>
        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Tell the application context to run the form on the same
            // thread as the other forms. Then prompt user to find file to save.
            SheetForm temp = new SheetForm();

            SheetFormAppContext.getAppContext().RunForm(temp);
            temp.control.newSpreadsheet();
        }
Beispiel #3
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // Start an application context and run one form inside it
            SheetFormAppContext appContext = SheetFormAppContext.getAppContext();

            appContext.RunForm(new SheetForm());
            Application.Run(appContext);
        }
        /// <summary>
        /// Handles when user pushed an arrow key, and then moves a cell over accordingly OR
        /// Handles when user does ctrl functions
        /// </summary>
        private void Form_KeyDown(object sender, KeyEventArgs e)
        {
            //Ctrl+key
            if (e.Control)
            {
                switch (e.KeyCode)
                {
                //+s to save
                case (Keys.S):
                    control.save();
                    break;

                //+n for new sheet
                case (Keys.N):
                    SheetForm temp = new SheetForm();
                    SheetFormAppContext.getAppContext().RunForm(temp);
                    temp.control.newSpreadsheet();
                    break;

                //+o for open sheet
                case (Keys.O):
                    control.load(spreadsheetPanel);
                    break;

                //+w to close
                case (Keys.W):
                    Close();
                    break;

                //Return with default so final bit doesn't get called
                default:
                    return;
                }
                //Prevents windows ding
                e.Handled          = true;
                e.SuppressKeyPress = true;
            }

            //Change selection based on which key is pushed
            spreadsheetPanel.GetSelection(out int x, out int y);
            switch (e.KeyData)
            {
            case (Keys.Up):
                spreadsheetPanel.SetSelection(x, y - 1);
                control.cellSelect(spreadsheetPanel);
                break;

            case (Keys.Down):
                spreadsheetPanel.SetSelection(x, y + 1);
                control.cellSelect(spreadsheetPanel);
                break;

            case (Keys.Left):
                spreadsheetPanel.SetSelection(x - 1, y);
                control.cellSelect(spreadsheetPanel);
                break;

            case (Keys.Right):
                spreadsheetPanel.SetSelection(x + 1, y);
                control.cellSelect(spreadsheetPanel);
                break;

            default: break;
            }
        }