public void SetList(List <ButtonMatrix.MatrixObject> _myList, ButtonMatrix.MatrixObject _selectedObj = null) { myList = _myList; selectedObj = _selectedObj; idxFirstButtonCurrPage = 0; if (myList == null) { this.Visible = false; return; } autoDeselect = selectedObj == null; this.Visible = true; RefreshButtonMatrix(); }
/* * Sets up the button matrix and data source. Should be called from parent Form's constructor */ public void Setup(int _numRows, int _numCols, List <ButtonMatrix.MatrixObject> _myList, ButtonMatrix.MatrixObject _selectedObj = null) { //Set instance attributes numRows = _numRows; numCols = _numCols; numButtons = numRows * numCols; myButtons = new List <Button>(); //Firstly remove default row and column from this control and add new ones of the correct % for //the numCols x numRows matrix float rowPerc = 100 / numRows; float colPerc = 100 / numCols; tabLayoutInside.RowStyles.Clear(); tabLayoutInside.RowCount = numRows; tabLayoutInside.ColumnStyles.Clear(); tabLayoutInside.ColumnCount = numCols; for (int i = 0; i < numRows; i++) { tabLayoutInside.RowStyles.Add(new RowStyle(SizeType.Percent, rowPerc)); } for (int i = 0; i < numCols; i++) { tabLayoutInside.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, colPerc)); } //Add a Button control in each cell of the matrix for (int i = 0; i < numButtons; i++) { Button b = GetNewButton(); myButtons.Add(b); tabLayoutInside.Controls.Add(b); } SetList(_myList, _selectedObj); }