protected override void ScaleControl(SizeF_ factor, BoundsSpecified specified) { // Never change the MdiClient's location specified &= ~BoundsSpecified.Location; base.ScaleControl(factor, specified); }
public virtual SizeF_ SizeOfPosition(Graphics dc, int pos) { if (pos >= line.TextLengthWithoutEnding() && line.document.multiline) { return(SizeF_.Empty); } string text = line.text.ToString(pos, 1); switch ((int)text [0]) { case '\t': if (!line.document.multiline) { goto case 10; } SizeF_ res = TextBoxTextRenderer.MeasureText(dc, " ", font); res.Width *= 8.0F; return(res); case 10: case 13: return(TextBoxTextRenderer.MeasureText(dc, "\u000D", font)); } return(TextBoxTextRenderer.MeasureText(dc, text, font)); }
protected void AddCheck(int row, int col, int colspan, string text, bool check, int width, int height, EventHandler onCheck) { CheckBox ctl = new CheckBox(); ctl.Text = text; ctl.Checked = check; if (width == -1 && height == -1) { SizeF_ s = TextRenderer.MeasureString(text, ctl.Font); ctl.Width += (int)((float)s.Width / 62f); if (s.Height > ctl.Height) { ctl.Height = (int)s.Height; } } else { ctl.Width = width; ctl.Height = height; } if (onCheck != null) { ctl.CheckedChanged += onCheck; } table.Controls.Add(ctl, col, row); if (colspan > 1) { table.SetColumnSpan(ctl, colspan); } }
internal bool validation_failed; //track whether validation was cancelled by a validating control #region Public Constructors public ContainerControl() { active_control = null; unvalidated_control = null; ControlRemoved += new ControlEventHandler(OnControlRemoved); auto_scale_dimensions = SizeF_.Empty; auto_scale_mode = AutoScaleMode.Inherit; }
private void DrawGridItemLabel(GridEntry grid_item, PaintEventArgs pevent, int depth, Rectangle_ rect) { Font font = this.Font; Brush brush; if (grid_item.GridItemType == GridItemType.Category) { font = bold_font; brush = SystemBrushes.ControlText; pevent.Graphics.DrawString(grid_item.Label, font, brush, rect.X + 1, rect.Y + ENTRY_SPACING); if (grid_item == this.SelectedGridItem) { SizeF_ size = pevent.Graphics.MeasureString(grid_item.Label, font); ControlPaint.DrawFocusRectangle(pevent.Graphics, new Rectangle_(rect.X + 1, rect.Y + ENTRY_SPACING, (int)size.Width, (int)size.Height)); } } else { if (grid_item == this.SelectedGridItem) { Rectangle_ highlight = rect; if (depth > 1) { highlight.X -= V_INDENT; highlight.Width += V_INDENT; } pevent.Graphics.FillRectangle(SystemBrushes.Highlight, highlight); // Label brush = SystemBrushes.HighlightText; } else { brush = grid_item.IsReadOnly ? inactive_text_brush : SystemBrushes.ControlText; } } pevent.Graphics.DrawString(grid_item.Label, font, brush, new Rectangle_(rect.X + 1, rect.Y + ENTRY_SPACING, rect.Width - ENTRY_SPACING, rect.Height - ENTRY_SPACING), string_format); }
void OnPaintExamplePanel(object sender, PaintEventArgs e) { SolidBrush brush = ThemeEngine.Current.ResPool.GetSolidBrush(Color); e.Graphics.FillRectangle(ThemeEngine.Current.ResPool.GetSolidBrush(SystemColors.Control), 0, 0, 156, 40); SizeF_ fontSizeF = e.Graphics.MeasureString(example_panel_text, font); int text_width = (int)fontSizeF.Width; int text_height = (int)fontSizeF.Height; int x = (examplePanel.Width / 2) - (text_width / 2); if (x < 0) { x = 0; } int y = (examplePanel.Height / 2) - (text_height / 2); e.Graphics.DrawString(example_panel_text, font, brush, new Point_(x, y)); }
internal void PerformAutoScale(bool called_by_scale) { if ((AutoScaleMode == AutoScaleMode.Inherit) && !called_by_scale) { return; } if ((layout_suspended > 0) && !called_by_scale) { auto_scale_pending = true; return; } // Set this first so we don't get called again from // PerformDelayedAutoScale after ResumeLayout auto_scale_pending = false; SizeF_ factor = AutoScaleFactor; if (AutoScaleMode == AutoScaleMode.Inherit) { ContainerControl cc = FindContainer(this.Parent); if (cc != null) { factor = cc.AutoScaleFactor; } } if (factor != new SizeF_(1F, 1F)) { is_auto_scaling = true; SuspendLayout(); Scale(factor); ResumeLayout(false); is_auto_scaling = false; } auto_scale_dimensions = CurrentAutoScaleDimensions; }
internal static SizeF_ MeasureString(string text, Font font, SizeF_ layoutArea, StringFormat stringFormat, out int charactersFitted, out int linesFilled) { return(Hwnd.GraphicsContext.MeasureString(text, font, layoutArea, stringFormat, out charactersFitted, out linesFilled)); }
internal static SizeF_ MeasureString(string text, Font font, SizeF_ layoutArea, StringFormat stringFormat) { return(Hwnd.GraphicsContext.MeasureString(text, font, layoutArea, stringFormat)); }
protected override void ScaleControl(SizeF_ factor, BoundsSpecified specified) { base.ScaleControl(factor, specified); }
protected virtual int DrawTab(Graphics dc, System.Windows.Forms.TabPage page, System.Windows.Forms.TabControl tab, Rectangle_ bounds, bool is_selected) { Rectangle_ interior; int res = bounds.Width; dc.FillRectangle(ResPool.GetSolidBrush(tab.BackColor), bounds); if (tab.Appearance == TabAppearance.Buttons || tab.Appearance == TabAppearance.FlatButtons) { // Separators if (tab.Appearance == TabAppearance.FlatButtons) { int width = bounds.Width; bounds.Width += (flatButtonSpacing - 2); res = bounds.Width; if (tab.Alignment == TabAlignment.Top || tab.Alignment == TabAlignment.Bottom) { ThemeEngine.Current.CPDrawBorder3D(dc, bounds, Border3DStyle.Etched, Border3DSide.Right); } else { ThemeEngine.Current.CPDrawBorder3D(dc, bounds, Border3DStyle.Etched, Border3DSide.Top); } bounds.Width = width; } if (is_selected) { ThemeEngine.Current.CPDrawBorder3D(dc, bounds, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom); } else if (tab.Appearance != TabAppearance.FlatButtons) { ThemeEngine.Current.CPDrawBorder3D(dc, bounds, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom); } } else { CPColor cpcolor = ResPool.GetCPColor(tab.BackColor); Pen light = ResPool.GetPen(cpcolor.LightLight); switch (tab.Alignment) { case TabAlignment.Top: dc.DrawLine(light, bounds.Left, bounds.Bottom - 1, bounds.Left, bounds.Top + 3); dc.DrawLine(light, bounds.Left, bounds.Top + 3, bounds.Left + 2, bounds.Top); dc.DrawLine(light, bounds.Left + 2, bounds.Top, bounds.Right - 3, bounds.Top); dc.DrawLine(SystemPens.ControlDark, bounds.Right - 2, bounds.Top + 1, bounds.Right - 2, bounds.Bottom - 1); dc.DrawLine(SystemPens.ControlDarkDark, bounds.Right - 2, bounds.Top + 1, bounds.Right - 1, bounds.Top + 2); dc.DrawLine(SystemPens.ControlDarkDark, bounds.Right - 1, bounds.Top + 2, bounds.Right - 1, bounds.Bottom - 1); break; case TabAlignment.Bottom: dc.DrawLine(light, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom - 2); dc.DrawLine(light, bounds.Left, bounds.Bottom - 2, bounds.Left + 3, bounds.Bottom); dc.DrawLine(SystemPens.ControlDarkDark, bounds.Left + 3, bounds.Bottom, bounds.Right - 3, bounds.Bottom); dc.DrawLine(SystemPens.ControlDark, bounds.Left + 3, bounds.Bottom - 1, bounds.Right - 3, bounds.Bottom - 1); dc.DrawLine(SystemPens.ControlDark, bounds.Right - 2, bounds.Bottom - 1, bounds.Right - 2, bounds.Top + 1); dc.DrawLine(SystemPens.ControlDarkDark, bounds.Right - 2, bounds.Bottom - 1, bounds.Right - 1, bounds.Bottom - 2); dc.DrawLine(SystemPens.ControlDarkDark, bounds.Right - 1, bounds.Bottom - 2, bounds.Right - 1, bounds.Top + 1); break; case TabAlignment.Left: dc.DrawLine(light, bounds.Left - 2, bounds.Top, bounds.Right, bounds.Top); dc.DrawLine(light, bounds.Left, bounds.Top + 2, bounds.Left - 2, bounds.Top); dc.DrawLine(light, bounds.Left, bounds.Top + 2, bounds.Left, bounds.Bottom - 2); dc.DrawLine(SystemPens.ControlDark, bounds.Left, bounds.Bottom - 2, bounds.Left + 2, bounds.Bottom - 1); dc.DrawLine(SystemPens.ControlDark, bounds.Left + 2, bounds.Bottom - 1, bounds.Right, bounds.Bottom - 1); dc.DrawLine(SystemPens.ControlDarkDark, bounds.Left + 2, bounds.Bottom, bounds.Right, bounds.Bottom); break; default: // TabAlignment.Right dc.DrawLine(light, bounds.Left, bounds.Top, bounds.Right - 3, bounds.Top); dc.DrawLine(light, bounds.Right - 3, bounds.Top, bounds.Right, bounds.Top + 3); dc.DrawLine(SystemPens.ControlDark, bounds.Right - 1, bounds.Top + 1, bounds.Right - 1, bounds.Bottom - 1); dc.DrawLine(SystemPens.ControlDark, bounds.Left, bounds.Bottom - 1, bounds.Right - 2, bounds.Bottom - 1); dc.DrawLine(SystemPens.ControlDarkDark, bounds.Right, bounds.Top + 3, bounds.Right, bounds.Bottom - 3); dc.DrawLine(SystemPens.ControlDarkDark, bounds.Left, bounds.Bottom, bounds.Right - 3, bounds.Bottom); break; } } Point_ padding = tab.Padding; interior = new Rectangle_(bounds.Left + padding.X - 1, // substract a little offset bounds.Top + padding.Y, bounds.Width - (padding.X * 2), bounds.Height - (padding.Y * 2)); if (tab.DrawMode == TabDrawMode.Normal && page.Text != null) { if (tab.Alignment == TabAlignment.Left) { dc.TranslateTransform(bounds.Left, bounds.Bottom); dc.RotateTransform(-90); dc.DrawString(page.Text, tab.Font, SystemBrushes.ControlText, tab.Padding.X - 2, // drawstring adds some extra unwanted leading spaces, so trimming tab.Padding.Y, defaultFormatting); dc.ResetTransform(); } else if (tab.Alignment == TabAlignment.Right) { dc.TranslateTransform(bounds.Right, bounds.Top); dc.RotateTransform(90); dc.DrawString(page.Text, tab.Font, SystemBrushes.ControlText, tab.Padding.X - 2, // drawstring adds some extra unwanted leading spaces, so trimming tab.Padding.Y, defaultFormatting); dc.ResetTransform(); } else { Rectangle_ str_rect = interior; if (is_selected) { // Reduce the interior Size_ to match the inner Size_ of non-selected tabs str_rect.X += selectedTabDelta.X; str_rect.Y += selectedTabDelta.Y; str_rect.Width -= selectedTabDelta.Width; str_rect.Height -= selectedTabDelta.Height; str_rect.Y -= selectedTabDelta.Y; // Move up the text / image of the selected tab } if (tab.ImageList != null && page.ImageIndex >= 0 && page.ImageIndex < tab.ImageList.Images.Count) { int image_x; if (tab.SizeMode != TabSizeMode.Fixed) { image_x = str_rect.X; } else { image_x = str_rect.X + (str_rect.Width - tab.ImageList.ImageSize.Width) / 2; if (page.Text != null) { SizeF_ textSize = dc.MeasureString(page.Text, page.Font, str_rect.Size); image_x -= (int)(textSize.Width / 2); } } int image_y = str_rect.Y + (str_rect.Height - tab.ImageList.ImageSize.Height) / 2; tab.ImageList.Draw(dc, new Point_(image_x, image_y), page.ImageIndex); str_rect.X += tab.ImageList.ImageSize.Width + 2; str_rect.Width -= tab.ImageList.ImageSize.Width + 2; } dc.DrawString(page.Text, tab.Font, SystemBrushes.ControlText, str_rect, defaultFormatting); } } else if (page.Text != null) { DrawItemState state = DrawItemState.None; if (page == tab.SelectedTab) { state |= DrawItemState.Selected; } DrawItemEventArgs e = new DrawItemEventArgs(dc, tab.Font, bounds, tab.IndexForTabPage(page), state, page.ForeColor, page.BackColor); tab.OnDrawItemInternal(e); return(res); } // TabControl ignores the value of ShowFocusCues if (page.Parent.Focused && is_selected) { Rectangle_ focus_rect = bounds; focus_rect.Inflate(-2, -2); ThemeEngine.Current.CPDrawFocusRectangle(dc, focus_rect, tab.BackColor, tab.ForeColor); } return(res); }
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); if (max_width > 500) { float dx; using (Graphics g = this.CreateGraphics ()) { dx = g.DpiX; } int new_max_width = (int) (dx * 5.0); // aim for text no wider than 5.0 inches if (new_max_width < max_width) max_width = new_max_width; } // First we have to know the Size_ of text + image int iconImageWidth = 0; if (icon_image != null) iconImageWidth = icon_image.Width + 10; SizeF_ tsize = TextRenderer.MeasureText (msgbox_text, this.Font, new Size_ (max_width - iconImageWidth, int.MaxValue), TextFormatFlags.WordBreak); text_rect = new RectangleF (); text_rect.Height = tsize.Height; if (icon_image != null) { tsize.Width += iconImageWidth; 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; text_rect.Height += space_border; // 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)); text_rect.Width = new_size.Width - iconImageWidth; // 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; } } }
protected new virtual Rectangle_ GetScaledBounds(Rectangle_ bounds, SizeF_ factor, BoundsSpecified specified) { throw new NotImplementedException("COM/ActiveX support is not implemented"); }