GetBestHeight() public method

Gets the height of the best.
public GetBestHeight ( ) : int
return int
コード例 #1
0
        /// <summary>
        /// Builds the form.
        /// </summary>
        public void BuildForm( )
        {
            int form_height = 0;

            // Setup Main Instruction
            switch (_mainIcon)
            {
            case SysIcons.Information:
                imgMain.Image = SystemIcons.Information.ToBitmap( );
                break;

            case SysIcons.Question:
                imgMain.Image = SystemIcons.Question.ToBitmap( );
                break;

            case SysIcons.Warning:
                imgMain.Image = SystemIcons.Warning.ToBitmap( );
                break;

            case SysIcons.Error:
                imgMain.Image = SystemIcons.Error.ToBitmap( );
                break;
            }

            //AdjustLabelHeight(lbMainInstruction);
            //pnlMainInstruction.Height = Math.Max(41, lbMainInstruction.Height + 16);
            if (_mainInstructionHeight == 0)
            {
                GetMainInstructionTextSizeF( );
            }
            pnlMainInstruction.Height = Math.Max(41, _mainInstructionHeight + 16);

            form_height += pnlMainInstruction.Height;

            // Setup Content
            pnlContent.Visible = (Content != "");
            if (Content != "")
            {
                AdjustLabelHeight(lbContent);
                pnlContent.Height = lbContent.Height + 4;
                form_height      += pnlContent.Height;
            }

            bool show_verify_checkbox = (cbVerify.Text != "");

            cbVerify.Visible = show_verify_checkbox;

            // Setup Expanded Info and Buttons panels
            if (ExpandedInfo == "")
            {
                pnlExpandedInfo.Visible   = false;
                lbShowHideDetails.Visible = false;
                cbVerify.Top      = 12;
                pnlButtons.Height = 40;
            }
            else
            {
                AdjustLabelHeight(lbExpandedInfo);
                pnlExpandedInfo.Height       = lbExpandedInfo.Height + 4;
                pnlExpandedInfo.Visible      = _expanded;
                lbShowHideDetails.Text       = (_expanded ? "        Hide details" : "        Show details");
                lbShowHideDetails.ImageIndex = (_expanded ? 0 : 3);
                if (!show_verify_checkbox)
                {
                    pnlButtons.Height = 40;
                }
                if (_expanded)
                {
                    form_height += pnlExpandedInfo.Height;
                }
            }

            // Setup RadioButtons
            pnlRadioButtons.Visible = (_radioButtons != "");
            if (_radioButtons != "")
            {
                string[] arr        = _radioButtons.Split(new char[] { '|' });
                int      pnl_height = 12;
                for (int i = 0; i < arr.Length; i++)
                {
                    RadioButton rb = new RadioButton( );
                    rb.Parent   = pnlRadioButtons;
                    rb.Location = new Point(60, 4 + (i * rb.Height));
                    rb.Text     = arr[i];
                    rb.Tag      = i;
                    rb.Checked  = (_initialRadioButtonIndex == i);
                    rb.Width    = this.Width - rb.Left - 15;
                    pnl_height += rb.Height;
                    _radioButtonCtrls.Add(rb);
                }
                pnlRadioButtons.Height = pnl_height;
                form_height           += pnlRadioButtons.Height;
            }

            // Setup CommandButtons
            pnlCommandButtons.Visible = (_commandButtons != "");
            if (_commandButtons != "")
            {
                string[] arr        = _commandButtons.Split(new char[] { '|' });
                int      t          = 8;
                int      pnl_height = 16;
                for (int i = 0; i < arr.Length; i++)
                {
                    CommandButton btn = new CommandButton( );
                    btn.Parent   = pnlCommandButtons;
                    btn.Location = new Point(50, t);
                    if (_isVista) // <- tweak font if vista
                    {
                        btn.Font = new Font(btn.Font, FontStyle.Regular);
                    }
                    btn.Text    = arr[i];
                    btn.Size    = new Size(this.Width - btn.Left - 15, btn.GetBestHeight( ));
                    t          += btn.Height;
                    pnl_height += btn.Height;
                    btn.Tag     = i;
                    btn.Click  += new EventHandler(CommandButton_Click);
                }
                pnlCommandButtons.Height = pnl_height;
                form_height += pnlCommandButtons.Height;
            }

            // Setup Buttons
            switch (_buttons)
            {
            case TaskDialogButtons.YesNo:
                bt1.Visible       = false;
                bt2.Text          = "&Yes";
                bt2.DialogResult  = DialogResult.Yes;
                bt3.Text          = "&No";
                bt3.DialogResult  = DialogResult.No;
                this.AcceptButton = bt2;
                this.CancelButton = bt3;
                break;

            case TaskDialogButtons.YesNoCancel:
                bt1.Text          = "&Yes";
                bt1.DialogResult  = DialogResult.Yes;
                bt2.Text          = "&No";
                bt2.DialogResult  = DialogResult.No;
                bt3.Text          = "&Cancel";
                bt3.DialogResult  = DialogResult.Cancel;
                this.AcceptButton = bt1;
                this.CancelButton = bt3;
                break;

            case TaskDialogButtons.OKCancel:
                bt1.Visible       = false;
                bt2.Text          = "&OK";
                bt2.DialogResult  = DialogResult.OK;
                bt3.Text          = "&Cancel";
                bt3.DialogResult  = DialogResult.Cancel;
                this.AcceptButton = bt2;
                this.CancelButton = bt3;
                break;

            case TaskDialogButtons.OK:
                bt1.Visible       = false;
                bt2.Visible       = false;
                bt3.Text          = "&OK";
                bt3.DialogResult  = DialogResult.OK;
                this.AcceptButton = bt3;
                this.CancelButton = bt3;
                break;

            case TaskDialogButtons.Close:
                bt1.Visible       = false;
                bt2.Visible       = false;
                bt3.Text          = "&Close";
                bt3.DialogResult  = DialogResult.Cancel;
                this.CancelButton = bt3;
                break;

            case TaskDialogButtons.Cancel:
                bt1.Visible       = false;
                bt2.Visible       = false;
                bt3.Text          = "&Cancel";
                bt3.DialogResult  = DialogResult.Cancel;
                this.CancelButton = bt3;
                break;

            case TaskDialogButtons.None:
                bt1.Visible = false;
                bt2.Visible = false;
                bt3.Visible = false;
                break;
            }

            this.ControlBox = (Buttons == TaskDialogButtons.Cancel ||
                               Buttons == TaskDialogButtons.Close ||
                               Buttons == TaskDialogButtons.OKCancel ||
                               Buttons == TaskDialogButtons.YesNoCancel);

            if (!show_verify_checkbox && ExpandedInfo == "" && _buttons == TaskDialogButtons.None)
            {
                pnlButtons.Visible = false;
            }
            else
            {
                form_height += pnlButtons.Height;
            }

            pnlFooter.Visible = (Footer != "");
            if (Footer != "")
            {
                AdjustLabelHeight(lbFooter);
                pnlFooter.Height = Math.Max(28, lbFooter.Height + 16);
                switch (_footerIcon)
                {
                case SysIcons.Information:
                    imgFooter.Image = SystemIcons.Information.ToBitmap( ).GetThumbnailImage(16, 16, null, IntPtr.Zero);
                    break;

                case SysIcons.Question:
                    imgFooter.Image = SystemIcons.Question.ToBitmap( ).GetThumbnailImage(16, 16, null, IntPtr.Zero);
                    break;

                case SysIcons.Warning:
                    imgFooter.Image = SystemIcons.Warning.ToBitmap( ).GetThumbnailImage(16, 16, null, IntPtr.Zero);
                    break;

                case SysIcons.Error:
                    imgFooter.Image = SystemIcons.Error.ToBitmap( ).GetThumbnailImage(16, 16, null, IntPtr.Zero);
                    break;
                }
                form_height += pnlFooter.Height;
            }

            this.ClientSize = new Size(ClientSize.Width, form_height);

            _formBuilt = true;
        }
コード例 #2
0
        /// <summary>
        /// Builds the form.
        /// </summary>
        public void BuildForm( )
        {
            int form_height = 0;

              // Setup Main Instruction
              switch ( _mainIcon ) {
            case SysIcons.Information:
              imgMain.Image = SystemIcons.Information.ToBitmap ( );
              break;
            case SysIcons.Question:
              imgMain.Image = SystemIcons.Question.ToBitmap ( );
              break;
            case SysIcons.Warning:
              imgMain.Image = SystemIcons.Warning.ToBitmap ( );
              break;
            case SysIcons.Error:
              imgMain.Image = SystemIcons.Error.ToBitmap ( );
              break;
              }

              //AdjustLabelHeight(lbMainInstruction);
              //pnlMainInstruction.Height = Math.Max(41, lbMainInstruction.Height + 16);
              if ( _mainInstructionHeight == 0 )
            GetMainInstructionTextSizeF ( );
              pnlMainInstruction.Height = Math.Max ( 41, _mainInstructionHeight + 16 );

              form_height += pnlMainInstruction.Height;

              // Setup Content
              pnlContent.Visible = ( Content != "" );
              if ( Content != "" ) {
            AdjustLabelHeight ( lbContent );
            pnlContent.Height = lbContent.Height + 4;
            form_height += pnlContent.Height;
              }

              bool show_verify_checkbox = ( cbVerify.Text != "" );
              cbVerify.Visible = show_verify_checkbox;

              // Setup Expanded Info and Buttons panels
              if ( ExpandedInfo == "" ) {
            pnlExpandedInfo.Visible = false;
            lbShowHideDetails.Visible = false;
            cbVerify.Top = 12;
            pnlButtons.Height = 40;
              } else {
            AdjustLabelHeight ( lbExpandedInfo );
            pnlExpandedInfo.Height = lbExpandedInfo.Height + 4;
            pnlExpandedInfo.Visible = _expanded;
            lbShowHideDetails.Text = ( _expanded ? "        Hide details" : "        Show details" );
            lbShowHideDetails.ImageIndex = ( _expanded ? 0 : 3 );
            if ( !show_verify_checkbox )
              pnlButtons.Height = 40;
            if ( _expanded )
              form_height += pnlExpandedInfo.Height;
              }

              // Setup RadioButtons
              pnlRadioButtons.Visible = ( _radioButtons != "" );
              if ( _radioButtons != "" ) {
            string[ ] arr = _radioButtons.Split ( new char[ ] { '|' } );
            int pnl_height = 12;
            for ( int i = 0; i < arr.Length; i++ ) {
              RadioButton rb = new RadioButton ( );
              rb.Parent = pnlRadioButtons;
              rb.Location = new Point ( 60, 4 + ( i * rb.Height ) );
              rb.Text = arr[ i ];
              rb.Tag = i;
              rb.Checked = ( _initialRadioButtonIndex == i );
              rb.Width = this.Width - rb.Left - 15;
              pnl_height += rb.Height;
              _radioButtonCtrls.Add ( rb );
            }
            pnlRadioButtons.Height = pnl_height;
            form_height += pnlRadioButtons.Height;
              }

              // Setup CommandButtons
              pnlCommandButtons.Visible = ( _commandButtons != "" );
              if ( _commandButtons != "" ) {
            string[ ] arr = _commandButtons.Split ( new char[ ] { '|' } );
            int t = 8;
            int pnl_height = 16;
            for ( int i = 0; i < arr.Length; i++ ) {
              CommandButton btn = new CommandButton ( );
              btn.Parent = pnlCommandButtons;
              btn.Location = new Point ( 50, t );
              if ( _isVista )  // <- tweak font if vista
            btn.Font = new Font ( btn.Font, FontStyle.Regular );
              btn.Text = arr[ i ];
              btn.Size = new Size ( this.Width - btn.Left - 15, btn.GetBestHeight ( ) );
              t += btn.Height;
              pnl_height += btn.Height;
              btn.Tag = i;
              btn.Click += new EventHandler ( CommandButton_Click );
            }
            pnlCommandButtons.Height = pnl_height;
            form_height += pnlCommandButtons.Height;
              }

              // Setup Buttons
              switch ( _buttons ) {
            case TaskDialogButtons.YesNo:
              bt1.Visible = false;
              bt2.Text = "&Yes";
              bt2.DialogResult = DialogResult.Yes;
              bt3.Text = "&No";
              bt3.DialogResult = DialogResult.No;
              this.AcceptButton = bt2;
              this.CancelButton = bt3;
              break;
            case TaskDialogButtons.YesNoCancel:
              bt1.Text = "&Yes";
              bt1.DialogResult = DialogResult.Yes;
              bt2.Text = "&No";
              bt2.DialogResult = DialogResult.No;
              bt3.Text = "&Cancel";
              bt3.DialogResult = DialogResult.Cancel;
              this.AcceptButton = bt1;
              this.CancelButton = bt3;
              break;
            case TaskDialogButtons.OKCancel:
              bt1.Visible = false;
              bt2.Text = "&OK";
              bt2.DialogResult = DialogResult.OK;
              bt3.Text = "&Cancel";
              bt3.DialogResult = DialogResult.Cancel;
              this.AcceptButton = bt2;
              this.CancelButton = bt3;
              break;
            case TaskDialogButtons.OK:
              bt1.Visible = false;
              bt2.Visible = false;
              bt3.Text = "&OK";
              bt3.DialogResult = DialogResult.OK;
              this.AcceptButton = bt3;
              this.CancelButton = bt3;
              break;
            case TaskDialogButtons.Close:
              bt1.Visible = false;
              bt2.Visible = false;
              bt3.Text = "&Close";
              bt3.DialogResult = DialogResult.Cancel;
              this.CancelButton = bt3;
              break;
            case TaskDialogButtons.Cancel:
              bt1.Visible = false;
              bt2.Visible = false;
              bt3.Text = "&Cancel";
              bt3.DialogResult = DialogResult.Cancel;
              this.CancelButton = bt3;
              break;
            case TaskDialogButtons.None:
              bt1.Visible = false;
              bt2.Visible = false;
              bt3.Visible = false;
              break;
              }

              this.ControlBox = ( Buttons == TaskDialogButtons.Cancel ||
                         Buttons == TaskDialogButtons.Close ||
                         Buttons == TaskDialogButtons.OKCancel ||
                         Buttons == TaskDialogButtons.YesNoCancel );

              if ( !show_verify_checkbox && ExpandedInfo == "" && _buttons == TaskDialogButtons.None )
            pnlButtons.Visible = false;
              else
            form_height += pnlButtons.Height;

              pnlFooter.Visible = ( Footer != "" );
              if ( Footer != "" ) {
            AdjustLabelHeight ( lbFooter );
            pnlFooter.Height = Math.Max ( 28, lbFooter.Height + 16 );
            switch ( _footerIcon ) {
              case SysIcons.Information:
            imgFooter.Image = SystemIcons.Information.ToBitmap ( ).GetThumbnailImage ( 16, 16, null, IntPtr.Zero );
            break;
              case SysIcons.Question:
            imgFooter.Image = SystemIcons.Question.ToBitmap ( ).GetThumbnailImage ( 16, 16, null, IntPtr.Zero );
            break;
              case SysIcons.Warning:
            imgFooter.Image = SystemIcons.Warning.ToBitmap ( ).GetThumbnailImage ( 16, 16, null, IntPtr.Zero );
            break;
              case SysIcons.Error:
            imgFooter.Image = SystemIcons.Error.ToBitmap ( ).GetThumbnailImage ( 16, 16, null, IntPtr.Zero );
            break;
            }
            form_height += pnlFooter.Height;
              }

              this.ClientSize = new Size ( ClientSize.Width, form_height );

              _formBuilt = true;
        }