private void UpdateCommandButtons()
{
if (_commandButtons.Count == 0)
{
_panelMainCommands.Visible = false;
}
else
{
_panelMainCommands.Controls.Clear();
_panelMainCommands.Visible = true;
Size maxButtonSize = Size.Empty;
foreach (KryptonTaskDialogCommand command in _commandButtons)
{
// Create and add a new button instance
KryptonButton button = new KryptonButton();
button.ButtonStyle = ButtonStyle.Command;
button.StateCommon.Content.Image.ImageH = PaletteRelativeAlign.Near;
button.StateCommon.Content.ShortText.TextH = PaletteRelativeAlign.Near;
button.StateCommon.Content.LongText.TextH = PaletteRelativeAlign.Near;
button.Values.Text = command.Text;
button.Values.ExtraText = command.ExtraText;
button.Values.Image = command.Image;
button.Values.ImageTransparentColor = command.ImageTransparentColor;
button.Enabled = command.Enabled;
button.DialogResult = command.DialogResult;
button.Tag = command;
button.Click += new EventHandler(OnCommandClicked);
_panelMainCommands.Controls.Add(button);
// Note that largest button encountered
Size buttonSize = button.GetPreferredSize(Size.Empty);
maxButtonSize.Width = Math.Max(maxButtonSize.Width, buttonSize.Width);
maxButtonSize.Height = Math.Max(maxButtonSize.Height, buttonSize.Height);
}
// Enforce a maximum width to the commands
maxButtonSize.Width = Math.Min(Math.Max(maxButtonSize.Width, 150), 400);
// Position the buttons in a vertical stack and size owning panel
Point offset = new Point(BUTTON_GAP - 1, 2);
foreach (KryptonButton button in _panelMainCommands.Controls)
{
button.Location = offset;
button.Size = maxButtonSize;
offset.Y += maxButtonSize.Height;
}
// Size to the contained command controls
_panelMainCommands.Size = new Size(maxButtonSize.Width, offset.Y);
}
}