Esempio n. 1
0
        private void BuildFormSubArea( )
        {
            // Left side of the sub control area.
            // Check if there is any expanded information first.
            if ( !String.IsNullOrEmpty ( this.taskDialog.ExpandedInformation ) )
            {
                expandedInfoButton = new EmulateExpInfoButton (
                        this.isExpanded,
                        this.taskDialog.ExpandedControlText,
                        this.taskDialog.CollapsedControlText
                        );
                expandedInfoButton.Click += new EventHandler ( expandedInfoButton_Click );

                this.flowLayoutPanelSubAreaControls.Controls.Add ( expandedInfoButton );
                // Smallest element in this area.
                this.tableLayoutPanelSubArea.MinimumSize = new Size ( 0, 34 );
            }

            if ( !String.IsNullOrEmpty ( this.taskDialog.VerificationText ) )
            {
                CheckBox checkBox = new CheckBox ( );
                checkBox.Checked = this.taskDialog.VerificationFlagChecked;
                checkBox.Margin = new Padding ( 8, 5, 0, 5 );
                checkBox.MaximumSize = new Size ( 150, 0 );
                checkBox.Text = this.taskDialog.VerificationText;
                checkBox.Width = 165;

                // AdjustControls doesn't take in account the checkbox, so need
                // to work around it.
                Size size = AdjustControls.GetBestSize (
                    checkBox,
                    checkBox.Text,
                    new Rectangle ( 0, 0, checkBox.Width - 52, checkBox.Height )
                    );
                checkBox.Height = size.Height + 8;

                this.flowLayoutPanelSubAreaControls.Controls.Add ( checkBox );
            }

            // Right side of the sub control area.
            // If there is no button, by default there will be an "Okay" button.
            if ( this.taskDialog.CommonButtons.Equals ( TaskDialogCommonButtons.None ) &&
                this.taskDialog.Buttons.Length == 0 )
            {
                this.flowLayoutPanelSubAreaButtons.Controls.Add ( BuildControlButton ( (int)DialogResult.OK, DialogResult.OK.ToString ( ) ) );
            }
            else
            {
                int requiredTotalButtonsWidth = 0;

                TaskDialogCommonButtons[] commonButtons = (TaskDialogCommonButtons[])Enum.GetValues ( typeof ( TaskDialogCommonButtons ) );

                // Iterate through all the common buttons. Get by reverse order
                // as the layout direction is right to left.
                for ( int i = commonButtons.Length - 1; i >= 0; i-- )
                {
                    // There is no "None" button.
                    if ( !commonButtons[i].Equals ( TaskDialogCommonButtons.None ) )
                    {
                        // Now to check which button is needed.
                        if ( ( this.taskDialog.CommonButtons & commonButtons[i] ).Equals ( commonButtons[i] ) )
                        {
                            // TaskDialogCommonButtons enums is not the same as
                            // DialogResult enums. Need to use another way of
                            // getting the correct DialogResult value.
                            Button button = new Button ( );

                            // DialogResult does not contain a "Close" enum,
                            // return value by TaskDialog is int 8.
                            if ( commonButtons[i].Equals ( TaskDialogCommonButtons.Close ) )
                            {
                                button = BuildControlButton ( 8, TaskDialogCommonButtons.Close.ToString ( ) );
                            }
                            // No "Ok" button. Is it a typo for TaskDialogCommonButtons in TaskDialog.cs?
                            else if ( commonButtons[i].Equals ( TaskDialogCommonButtons.OK ) )
                            {
                                button = BuildControlButton ( (int)DialogResult.OK, DialogResult.OK.ToString ( ) );
                            }
                            else
                            {
                                DialogResult result = (DialogResult)Enum.Parse ( typeof ( DialogResult ), commonButtons[i].ToString ( ) );
                                button = BuildControlButton ( (int)result, result.ToString ( ) );
                            }

                            button.TabIndex = i + this.taskDialog.Buttons.Length;

                            this.flowLayoutPanelSubAreaButtons.Controls.Add ( button );

                            requiredTotalButtonsWidth += button.Width + button.Margin.Left + button.Margin.Right;
                        }
                    }
                }

                // Custom buttons. Get by reverse order as the layout direction
                // is right to left.
                if ( !this.taskDialog.UseCommandLinks )
                {
                    for ( int i = this.taskDialog.Buttons.Length - 1; i >= 0; i-- )
                    {
                        Button button = BuildControlButton ( this.taskDialog.Buttons[i].ButtonId, this.taskDialog.Buttons[i].ButtonText );
                        this.flowLayoutPanelSubAreaButtons.Controls.Add ( button );

                        button.TabIndex = i;

                        requiredTotalButtonsWidth += button.Width + button.Margin.Left + button.Margin.Right;
                    }
                }

                // Check if there is anything in the sub area.
                if ( ( requiredTotalButtonsWidth == 0 ) &&
                    ( String.IsNullOrEmpty ( this.taskDialog.ExpandedInformation ) ) &&
                    ( String.IsNullOrEmpty ( this.taskDialog.VerificationText ) ) )
                {
                    this.tableLayoutPanel1.Visible = false;
                    this.tableLayoutPanel1.Height = 0;
                    this.tableLayoutPanelSubArea.Visible = false;
                }
                else
                {
                    // Padding on the right.
                    requiredTotalButtonsWidth += 15;

                    if ( requiredTotalButtonsWidth > this.flowLayoutPanelSubAreaButtons.Width )
                    {
                        this.Width += requiredTotalButtonsWidth - this.flowLayoutPanelSubAreaButtons.Width;
                    }
                }
            }
        }
Esempio n. 2
0
        private void BuildFormSubArea( )
        {
            // Left side of the sub control area.
            // Check if there is any expanded information first.
            if (!String.IsNullOrEmpty(this.taskDialog.ExpandedInformation))
            {
                expandedInfoButton = new EmulateExpInfoButton(
                    this.isExpanded,
                    this.taskDialog.ExpandedControlText,
                    this.taskDialog.CollapsedControlText
                    );
                expandedInfoButton.Click += new EventHandler(expandedInfoButton_Click);

                this.flowLayoutPanelSubAreaControls.Controls.Add(expandedInfoButton);
                // Smallest element in this area.
                this.tableLayoutPanelSubArea.MinimumSize = new Size(0, 34);
            }

            if (!String.IsNullOrEmpty(this.taskDialog.VerificationText))
            {
                CheckBox checkBox = new CheckBox( );
                checkBox.Checked     = this.taskDialog.VerificationFlagChecked;
                checkBox.Margin      = new Padding(8, 5, 0, 5);
                checkBox.MaximumSize = new Size(150, 0);
                checkBox.Text        = this.taskDialog.VerificationText;
                checkBox.Width       = 165;

                // AdjustControls doesn't take in account the checkbox, so need
                // to work around it.
                Size size = AdjustControls.GetBestSize(
                    checkBox,
                    checkBox.Text,
                    new Rectangle(0, 0, checkBox.Width - 52, checkBox.Height)
                    );
                checkBox.Height = size.Height + 8;

                this.flowLayoutPanelSubAreaControls.Controls.Add(checkBox);
            }

            // Right side of the sub control area.
            // If there is no button, by default there will be an "Okay" button.
            if (this.taskDialog.CommonButtons.Equals(TaskDialogCommonButtons.None) &&
                this.taskDialog.Buttons.Length == 0)
            {
                this.flowLayoutPanelSubAreaButtons.Controls.Add(BuildControlButton((int)DialogResult.OK, DialogResult.OK.ToString( )));
            }
            else
            {
                int requiredTotalButtonsWidth = 0;

                TaskDialogCommonButtons[] commonButtons = (TaskDialogCommonButtons[])Enum.GetValues(typeof(TaskDialogCommonButtons));

                // Iterate through all the common buttons. Get by reverse order
                // as the layout direction is right to left.
                for (int i = commonButtons.Length - 1; i >= 0; i--)
                {
                    // There is no "None" button.
                    if (!commonButtons[i].Equals(TaskDialogCommonButtons.None))
                    {
                        // Now to check which button is needed.
                        if ((this.taskDialog.CommonButtons & commonButtons[i]).Equals(commonButtons[i]))
                        {
                            // TaskDialogCommonButtons enums is not the same as
                            // DialogResult enums. Need to use another way of
                            // getting the correct DialogResult value.
                            Button button = new Button( );

                            // DialogResult does not contain a "Close" enum,
                            // return value by TaskDialog is int 8.
                            if (commonButtons[i].Equals(TaskDialogCommonButtons.Close))
                            {
                                button = BuildControlButton(8, TaskDialogCommonButtons.Close.ToString( ));
                            }
                            // No "Ok" button. Is it a typo for TaskDialogCommonButtons in TaskDialog.cs?
                            else if (commonButtons[i].Equals(TaskDialogCommonButtons.OK))
                            {
                                button = BuildControlButton((int)DialogResult.OK, DialogResult.OK.ToString( ));
                            }
                            else
                            {
                                DialogResult result = (DialogResult)Enum.Parse(typeof(DialogResult), commonButtons[i].ToString( ));
                                button = BuildControlButton((int)result, result.ToString( ));
                            }

                            button.TabIndex = i + this.taskDialog.Buttons.Length;

                            this.flowLayoutPanelSubAreaButtons.Controls.Add(button);

                            requiredTotalButtonsWidth += button.Width + button.Margin.Left + button.Margin.Right;
                        }
                    }
                }

                // Custom buttons. Get by reverse order as the layout direction
                // is right to left.
                if (!this.taskDialog.UseCommandLinks)
                {
                    for (int i = this.taskDialog.Buttons.Length - 1; i >= 0; i--)
                    {
                        Button button = BuildControlButton(this.taskDialog.Buttons[i].ButtonId, this.taskDialog.Buttons[i].ButtonText);
                        this.flowLayoutPanelSubAreaButtons.Controls.Add(button);

                        button.TabIndex = i;

                        requiredTotalButtonsWidth += button.Width + button.Margin.Left + button.Margin.Right;
                    }
                }

                // Check if there is anything in the sub area.
                if ((requiredTotalButtonsWidth == 0) &&
                    (String.IsNullOrEmpty(this.taskDialog.ExpandedInformation)) &&
                    (String.IsNullOrEmpty(this.taskDialog.VerificationText)))
                {
                    this.tableLayoutPanel1.Visible       = false;
                    this.tableLayoutPanel1.Height        = 0;
                    this.tableLayoutPanelSubArea.Visible = false;
                }
                else
                {
                    // Padding on the right.
                    requiredTotalButtonsWidth += 15;

                    if (requiredTotalButtonsWidth > this.flowLayoutPanelSubAreaButtons.Width)
                    {
                        this.Width += requiredTotalButtonsWidth - this.flowLayoutPanelSubAreaButtons.Width;
                    }
                }
            }
        }