public static Drawing.SizeF GetOffsetsToDrawText(
            this StaticLayout target,
            float x,
            float y,
            float width,
            float height,
            HorizontalAlignment horizontalAlignment,
            VerticalAlignment verticalAlignment)
        {
            if (verticalAlignment != VerticalAlignment.Top)
            {
                Drawing.SizeF vTextFrameSize = target.GetTextSize();

                float vOffsetX = 0;
                float vOffsetY = 0;

                if (height > 0)
                {
                    if (verticalAlignment == VerticalAlignment.Bottom)
                    {
                        vOffsetY = height - vTextFrameSize.Height;
                    }
                    else
                    {
                        vOffsetY = (height - vTextFrameSize.Height) / 2;
                    }
                }

                return(new Drawing.SizeF(x + vOffsetX, y + vOffsetY));
            }

            return(new Drawing.SizeF(x, y));
        }
예제 #2
0
 /// <summary>
 /// Required method for Designer support - do not modify
 /// the contents of this method with the code editor.
 /// </summary>
 private void InitializeComponent()
 {
     _cancelButton   = new Button();
     _okButton       = new Button();
     _formatControl1 = new FormatControl();
     SuspendLayout();
     //
     // formatControl1
     //
     _formatControl1.Location = new Drawing.Point(10, 10);
     _formatControl1.Margin   = new Padding(0);
     _formatControl1.Name     = "formatControl1";
     _formatControl1.Size     = new Drawing.Size(376, 268);
     _formatControl1.TabIndex = 0;
     //
     // cancelButton
     //
     _cancelButton.Location     = new Drawing.Point(299, 288);
     _cancelButton.Name         = "cancelButton";
     _cancelButton.Size         = new Drawing.Size(87, 23);
     _cancelButton.TabIndex     = 2;
     _cancelButton.Text         = SR.DataGridView_Cancel;
     _cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
     _cancelButton.Click       += new EventHandler(cancelButton_Click);
     //
     // okButton
     //
     _okButton.Location     = new Drawing.Point(203, 288);
     _okButton.Name         = "okButton";
     _okButton.Size         = new Drawing.Size(87, 23);
     _okButton.TabIndex     = 1;
     _okButton.Text         = SR.DataGridView_OK;
     _okButton.DialogResult = System.Windows.Forms.DialogResult.OK;
     _okButton.Click       += new EventHandler(okButton_Click);
     //
     // Form1
     //
     AutoScaleMode       = System.Windows.Forms.AutoScaleMode.Font;
     AutoScaleDimensions = new Drawing.SizeF(6, 13);
     ClientSize          = new Drawing.Size(396, 295);
     AutoSize            = true;
     HelpButton          = true;
     MaximizeBox         = false;
     MinimizeBox         = false;
     FormBorderStyle     = FormBorderStyle.FixedDialog;
     StartPosition       = FormStartPosition.CenterScreen;
     ShowInTaskbar       = false;
     Icon = null;
     Name = "Form1";
     Controls.Add(_okButton);
     Controls.Add(_formatControl1);
     Controls.Add(_cancelButton);
     Padding            = new Padding(0);
     Text               = SR.FormatStringDialogTitle;
     HelpButtonClicked += new CancelEventHandler(FormatStringDialog_HelpButtonClicked);
     HelpRequested     += new HelpEventHandler(FormatStringDialog_HelpRequested);
     Load              += new EventHandler(FormatStringDialog_Load);
     ResumeLayout(false);
 }
예제 #3
0
        public static UIImage ScaleImage(this UIImage target, Drawing.SizeF size, bool disposeOriginal = false)
        {
            UIGraphics.BeginImageContext(size);
            target.Draw(new Drawing.RectangleF(new Drawing.PointF(0, 0), size));
            var image = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            if (disposeOriginal)
            {
                target.Dispose();
            }

            return(image);
        }
예제 #4
0
 public static SizeF AsSizeF(this Drawing.SizeF target)
 {
     return(new SizeF(target.Width, target.Height));
 }
예제 #5
0
            private void InitFormsSize()
            {
                int tb_width = 0;

                // Max width of messagebox must be 60% of screen width
                int max_width = (int)(Screen.GetWorkingArea(this).Width * 0.6);

                // First we have to know the size of text + image
                Drawing.SizeF tsize = TextRenderer.MeasureString(msgbox_text, this.Font, max_width);
                text_rect.Size = tsize;

                if (icon_image != null)
                {
                    tsize.Width += icon_image.Width + 10;
                    if (icon_image.Height > tsize.Height)
                    {
                        // Place text middle-right
                        text_rect.Location = new Point(icon_image.Width + space_image_text + space_border, (int)((icon_image.Height / 2) - (tsize.Height / 2)) + space_border);
                    }
                    else
                    {
                        text_rect.Location = new Point(icon_image.Width + space_image_text + space_border, 2 + space_border);
                    }
                    if (tsize.Height < icon_image.Height)
                    {
                        tsize.Height = icon_image.Height;
                    }
                }
                else
                {
                    text_rect.Location = new Point(space_border + button_space, space_border);
                }
                tsize.Height += space_border * 2;

                // Now we want to know the amount of buttons
                int buttoncount;

                switch (msgbox_buttons)
                {
                case MessageBoxButtons.OK:
                    buttoncount = 1;
                    break;

                case MessageBoxButtons.OKCancel:
                    buttoncount = 2;
                    break;

                case MessageBoxButtons.AbortRetryIgnore:
                    buttoncount = 3;
                    break;

                case MessageBoxButtons.YesNoCancel:
                    buttoncount = 3;
                    break;

                case MessageBoxButtons.YesNo:
                    buttoncount = 2;
                    break;

                case MessageBoxButtons.RetryCancel:
                    buttoncount = 2;
                    break;

                default:
                    buttoncount = 0;
                    break;
                }
                if (show_help)
                {
                    buttoncount++;
                }

                // Calculate the width based on amount of buttons
                tb_width = (button_width + button_space) * buttoncount;

                // The form caption can also make us bigger
                SizeF caption = TextRenderer.MeasureString(Text, new Font(DefaultFont, FontStyle.Bold));

                // Use the bigger of the caption size (plus some arbitrary borders/close button)
                // or the text size, up to 60% of the screen (max_size)
                Size new_size = new SizeF(Math.Min(Math.Max(caption.Width + 40, tsize.Width), max_width), tsize.Height).ToSize();

                // Now we choose the good size for the form
                if (new_size.Width > tb_width)
                {
                    this.ClientSize = new Size(new_size.Width + (space_border * 2), Height = new_size.Height + (space_border * 4));
                }
                else
                {
                    this.ClientSize = new Size(tb_width + (space_border * 2), Height = new_size.Height + (space_border * 4));
                }

                // Now we set the left of the buttons
                button_left = (this.ClientSize.Width / 2) - (tb_width / 2) + 5;
                AddButtons();
                size_known = true;

                // Still needs to implement defaultButton and options
                switch (msgbox_default)
                {
                case MessageBoxDefaultButton.Button2: {
                    if (this.buttons[1] != null)
                    {
                        ActiveControl = this.buttons[1];
                    }
                    break;
                }

                case MessageBoxDefaultButton.Button3: {
                    if (this.buttons[2] != null)
                    {
                        ActiveControl = this.buttons[2];
                    }
                    break;
                }
                }
            }