private void RepositionButtons() { if (this.Width <= 2 || this.Height <= 2) { return; } if (_buttons.Count == 0) { return; } const int OUTERMARGIN = 4; const int INNERMARGIN = 2; // Figure out the max button size, and how they should be tiled List <int> buttonsPerRow = GetButtonArrangement(out _buttonSize, INNERMARGIN, OUTERMARGIN); if (_buttonSize == -1) { MessageBox.Show("Buttons don't fit in the space provided", "Pie Panel Menu", MessageBoxButtons.OK, MessageBoxIcon.Error); _buttonSize = 1; } // Place and draw the buttons int buttonCntr = 0; for (int rowCntr = 0; rowCntr < buttonsPerRow.Count; rowCntr++) { // All buttons in this row will be at this y coord int y = this.Height - OUTERMARGIN - ((buttonsPerRow.Count - rowCntr) * _buttonSize) - ((buttonsPerRow.Count - rowCntr - 1) * INNERMARGIN); for (int colCntr = 0; colCntr < buttonsPerRow[rowCntr]; colCntr++) { #region Place Button // Figure out where this button will sit _buttons[buttonCntr].Rectangle = new Rectangle(OUTERMARGIN + (colCntr * _buttonSize) + (colCntr * INNERMARGIN), y, _buttonSize, _buttonSize); // Rebuild the graphics path //TODO: Support slightly rounded corners if (_buttons[buttonCntr].Outline != null) { _buttons[buttonCntr].Outline.Dispose(); _buttons[buttonCntr].Outline = null; } _buttons[buttonCntr].Outline = UtilityGDI.GetRoundedRectangle(_buttons[buttonCntr].Rectangle, _buttonSize / 3); // Draw the button DrawButton_Private(buttonCntr); #endregion // Point to the next button buttonCntr++; } } // Any time the layout changes, I should probably redraw this.Invalidate(); }