Exemple #1
0
        public UICell(UICellLogic logic, BoardLogic boardLogic, FreeContextMenuStrip contextMenu, Position position)
        {
            this.logic       = logic;
            this.boardLogic  = boardLogic;
            this.contextMenu = contextMenu;
            this.position    = position;

            InitializeComponent();

            // Initial state
            labelNumber.Dock         = DockStyle.Fill;
            labelNumber.ForeColor    = (Color)logic.Foreground;
            BackColor                = (Color)logic.Background;
            labelNumber.Text         = logic.Number;
            labelPossibles.ForeColor = (Color)logic.PossiblesForeground;
            labelPossibles.Text      = logic.Possibles;

            // Draw borders
            tableLayoutPanelBorders.CellPaint += OnCellPaint;

            // Listen to logic changes
            logic.PropertyChanged += OnPropertyChanged;

            // Listen to mouse clicks
            panelCell.MouseDown   += OnMouseDown;
            labelNumber.MouseDown += OnMouseDown;
        }
Exemple #2
0
        public MainWindow()
        {
            // Create logic
            logic      = new MainWindowLogic(this);
            boardLogic = logic.BoardLogic;

            // Create winforms widgets
            InitializeComponent();

            // Get settings
            Load += (s, e) => OnLoad();

            // Save settings on closing
            Closing += (s, e) => SaveSettings();

            // Build context menu
            var numberPicker = new NumberPicker(boardLogic);

            contextMenu = new FreeContextMenuStrip(numberPicker);
            numberPicker.ParentContextMenuStrip = contextMenu;

            // Regain focus when context menu goes away
            contextMenu.Closed += (e, s) => Focus();

            // Create the cells
            CreateCells();

            // Initial state
            buttonUndo.Enabled  = boardLogic.Undo.CanExecute();
            buttonRedo.Enabled  = boardLogic.Redo.CanExecute();
            buttonReset.Enabled = boardLogic.Reset.CanExecute();

            // Listen to logic events
            boardLogic.Undo.CanExecuteChanged  += (s, e) => buttonUndo.Enabled = boardLogic.Undo.CanExecute();
            boardLogic.Redo.CanExecuteChanged  += (s, e) => buttonRedo.Enabled = boardLogic.Redo.CanExecute();
            boardLogic.Reset.CanExecuteChanged += (s, e) => buttonReset.Enabled = boardLogic.Reset.CanExecute();
        }