// private methods... #region AddRedirectControls private void AddRedirectControls(Redirects redirects) { const int INT_TopMargin = 5; const int INT_SpaceBetweenButtons = 4; int yPos = lblOptions.Bottom + INT_TopMargin; int longestButtonTextWidth = 0; foreach (CompatibilityRedirect redirect in redirects) { Graphics graphics = Graphics.FromHwnd(Handle); SizeF rect = graphics.MeasureString(redirect.ButtonText, Font); int thisWidth = (int)Math.Ceiling(rect.Width); if (thisWidth > longestButtonTextWidth) { longestButtonTextWidth = thisWidth; } } const int INT_ExplanationLabelMargin = 8; // Distance between disabled button and explaning label. int xPos = 8; int buttonWidth = longestButtonTextWidth + 16; int longestWidth = buttonWidth; foreach (CompatibilityRedirect redirect in redirects) { RedirectButton button = new RedirectButton(redirect.Command, redirect.Parameters); pnlOptions.Controls.Add(button); button.Text = redirect.ButtonText; button.Enabled = redirect.IsAvailable; button.Left = xPos; button.Width = buttonWidth; toolTip1.SetToolTip(button, redirect.Description); button.Top = yPos; button.Click += new EventHandler(redirectButton_Click); if (!redirect.IsAvailable) { Label explanationLabel = new Label(); pnlOptions.Controls.Add(explanationLabel); explanationLabel.Top = yPos; explanationLabel.Left = button.Right + INT_ExplanationLabelMargin; explanationLabel.AutoSize = true; explanationLabel.Text = redirect.AvailabilityHint; explanationLabel.ForeColor = SystemColors.GrayText; if (longestWidth < explanationLabel.Right) { longestWidth = explanationLabel.Right; } } yPos += button.Height + INT_SpaceBetweenButtons; } pnlOptions.Height = yPos; pnlOptions.Width = longestWidth; }
// private methods... #region AddRedirectControls private void AddRedirectControls(Redirects redirects) { const int INT_TopMargin = 5; const int INT_SpaceBetweenButtons = 4; int yPos = lblOptions.Bottom + INT_TopMargin; int longestButtonTextWidth = 0; foreach (CompatibilityRedirect redirect in redirects) { Graphics graphics = Graphics.FromHwnd(Handle); SizeF rect = graphics.MeasureString(redirect.ButtonText, Font); int thisWidth = (int)Math.Ceiling(rect.Width); if (thisWidth > longestButtonTextWidth) longestButtonTextWidth = thisWidth; } const int INT_ExplanationLabelMargin = 8; // Distance between disabled button and explaning label. int xPos = 8; int buttonWidth = longestButtonTextWidth + 16; int longestWidth = buttonWidth; foreach (CompatibilityRedirect redirect in redirects) { RedirectButton button = new RedirectButton(redirect.Command, redirect.Parameters); pnlOptions.Controls.Add(button); button.Text = redirect.ButtonText; button.Enabled = redirect.IsAvailable; button.Left = xPos; button.Width = buttonWidth; toolTip1.SetToolTip(button, redirect.Description); button.Top = yPos; button.Click += new EventHandler(redirectButton_Click); if (!redirect.IsAvailable) { Label explanationLabel = new Label(); pnlOptions.Controls.Add(explanationLabel); explanationLabel.Top = yPos; explanationLabel.Left = button.Right + INT_ExplanationLabelMargin; explanationLabel.AutoSize = true; explanationLabel.Text = redirect.AvailabilityHint; explanationLabel.ForeColor = SystemColors.GrayText; if (longestWidth < explanationLabel.Right) longestWidth = explanationLabel.Right; } yPos += button.Height + INT_SpaceBetweenButtons; } pnlOptions.Height = yPos; pnlOptions.Width = longestWidth; }
// event handlers... #region redirectButton_Click void redirectButton_Click(object sender, EventArgs e) { RedirectButton redirectButton = sender as RedirectButton; if (redirectButton == null) { return; } _Command = redirectButton.Command; _Parameters = redirectButton.Parameters; _Result = CompatibilityResult.ExecuteCommand; _PersistResponse = chkAlwaysPerformThisAction.Visible && chkAlwaysPerformThisAction.Checked; Close(); }