Exemple #1
0
        /*
         * Respond to one of the matrix buttons being clicked.
         */
        private void btnMatrix_Click(object sender, EventArgs e)
        {
            if (selectedObj != null)
            {
                // Set the colour of the currently selected button back to normal.
                int idx = displayedObjs.FindIndex(o => o == selectedObj);
                if (idx != -1)
                {
                    SetButtonColor(myButtons[idx], selectedObj.GetNormalColor());
                }
            }

            // Set the colour of the newly selected button to its highlighted colour.
            int idxButtonSelected = myButtons.IndexOf((Button)sender);

            selectedObj = displayedObjs[idxButtonSelected];
            SetButtonColor(myButtons[idxButtonSelected], selectedObj.GetSelectedColor());

            // Raise ButtonSelected event
            var args = new ButtonSelectedEventArgs();

            args.obj = selectedObj;
            OnButtonSelected(args);
        }
Exemple #2
0
        private void RefreshButtonMatrix()
        {
            int numberOfButtons = 0;

            idxFirstButtonNextPage = 0;
            displayedObjs          = new List <MatrixObject>();

            if (autoDeselect)
            {
                // Effectively de-select current selection
                selectedObj = null;
            }

            for (int i = idxFirstButtonCurrPage; i < myList.Count; i++)
            {
                if (!myList[i].MatchesFilter())
                {
                    continue;
                }

                if (numberOfButtons >= numButtons)
                {
                    idxFirstButtonNextPage = i;
                    break;
                }
                myButtons[numberOfButtons].Text    = myList[i].ToString();
                myButtons[numberOfButtons].Visible = true;

                Color col;
                if (myList[i] == selectedObj)
                {
                    col = myList[i].GetSelectedColor();
                }
                else
                {
                    col = myList[i].GetNormalColor();
                }
                SetButtonColor(myButtons[numberOfButtons], col);

                displayedObjs.Add(myList[i]);
                numberOfButtons++;
            }
            for (int i = numberOfButtons; i < numButtons; i++)
            {
                myButtons[i].Visible = false;
            }

            // Set visibility of Page Up and Down buttons depending on whether there's next/previous pages to display
            btnPageDown.Visible = idxFirstButtonNextPage > 0;
            btnPageUp.Visible   = idxFirstButtonCurrPage > 0;

            var args = new ButtonSelectedEventArgs();

            if (numberOfButtons == 1)
            {
                //Automatically select a button if it's the only one displayed
                selectedObj = displayedObjs[0];
                SetButtonColor(myButtons[0], selectedObj.GetSelectedColor());
                args.obj = selectedObj;
                OnButtonSelected(args);
            }
        }