public virtual void Draw(Graphics g, Rectangle_ bounds, ButtonThemeState state, Color_ backColor, Color_ foreColor) { bool is_themecolor = backColor.ToArgb() == ThemeEngine.Current.ColorControl.ToArgb() || backColor == Color_.Empty ? true : false; CPColor cpcolor = is_themecolor ? CPColor.Empty : ResPool.GetCPColor(backColor); Pen pen; switch (state) { case ButtonThemeState.Normal: case ButtonThemeState.Entered: case ButtonThemeState.Disabled: pen = is_themecolor ? SystemPens.ControlLightLight : ResPool.GetPen(cpcolor.LightLight); g.DrawLine(pen, bounds.X, bounds.Y, bounds.X, bounds.Bottom - 2); g.DrawLine(pen, bounds.X + 1, bounds.Y, bounds.Right - 2, bounds.Y); pen = is_themecolor ? SystemPens.Control : ResPool.GetPen(backColor); g.DrawLine(pen, bounds.X + 1, bounds.Y + 1, bounds.X + 1, bounds.Bottom - 3); g.DrawLine(pen, bounds.X + 2, bounds.Y + 1, bounds.Right - 3, bounds.Y + 1); pen = is_themecolor ? SystemPens.ControlDark : ResPool.GetPen(cpcolor.Dark); g.DrawLine(pen, bounds.X + 1, bounds.Bottom - 2, bounds.Right - 2, bounds.Bottom - 2); g.DrawLine(pen, bounds.Right - 2, bounds.Y + 1, bounds.Right - 2, bounds.Bottom - 3); pen = is_themecolor ? SystemPens.ControlDarkDark : ResPool.GetPen(cpcolor.DarkDark); g.DrawLine(pen, bounds.X, bounds.Bottom - 1, bounds.Right - 1, bounds.Bottom - 1); g.DrawLine(pen, bounds.Right - 1, bounds.Y, bounds.Right - 1, bounds.Bottom - 2); break; case ButtonThemeState.Pressed: g.DrawRectangle(ResPool.GetPen(foreColor), bounds.X, bounds.Y, bounds.Width - 1, bounds.Height - 1); bounds.Inflate(-1, -1); pen = is_themecolor ? SystemPens.ControlDark : ResPool.GetPen(cpcolor.Dark); g.DrawRectangle(pen, bounds.X, bounds.Y, bounds.Width - 1, bounds.Height - 1); break; case ButtonThemeState.Default: g.DrawRectangle(ResPool.GetPen(foreColor), bounds.X, bounds.Y, bounds.Width - 1, bounds.Height - 1); bounds.Inflate(-1, -1); pen = is_themecolor ? SystemPens.ControlLightLight : ResPool.GetPen(cpcolor.LightLight); g.DrawLine(pen, bounds.X, bounds.Y, bounds.X, bounds.Bottom - 2); g.DrawLine(pen, bounds.X + 1, bounds.Y, bounds.Right - 2, bounds.Y); pen = is_themecolor ? SystemPens.Control : ResPool.GetPen(backColor); g.DrawLine(pen, bounds.X + 1, bounds.Y + 1, bounds.X + 1, bounds.Bottom - 3); g.DrawLine(pen, bounds.X + 2, bounds.Y + 1, bounds.Right - 3, bounds.Y + 1); pen = is_themecolor ? SystemPens.ControlDark : ResPool.GetPen(cpcolor.Dark); g.DrawLine(pen, bounds.X + 1, bounds.Bottom - 2, bounds.Right - 2, bounds.Bottom - 2); g.DrawLine(pen, bounds.Right - 2, bounds.Y + 1, bounds.Right - 2, bounds.Bottom - 3); pen = is_themecolor ? SystemPens.ControlDarkDark : ResPool.GetPen(cpcolor.DarkDark); g.DrawLine(pen, bounds.X, bounds.Bottom - 1, bounds.Right - 1, bounds.Bottom - 1); g.DrawLine(pen, bounds.Right - 1, bounds.Y, bounds.Right - 1, bounds.Bottom - 2); break; } }
private bool MouseInControl(Control control, bool fuzzy) { Point_ m; Point_ c; Size_ cw; if (control == null) { return(false); } m = Control.MousePosition; c = new Point_(control.Bounds.X, control.Bounds.Y); if (control.Parent != null) { c = control.Parent.PointToScreen(c); } cw = control.ClientSize; Rectangle_ rect = new Rectangle_(c, cw); // // We won't get mouse move events on all platforms with the exact same // frequency, so cheat a bit. if (fuzzy) { rect.Inflate(2, 2); } return(rect.Contains(m)); }
public static void DrawButton(Graphics g, Rectangle_ bounds, string buttonText, Font font, TextFormatFlags flags, Image image, Rectangle_ imageBounds, bool focused, PushButtonState state) { if (Application.RenderWithVisualStyles || always_use_visual_styles == true) { VisualStyleRenderer vsr = GetPushButtonRenderer(state); vsr.DrawBackground(g, bounds); if (image != null) { vsr.DrawImage(g, imageBounds, image); } } else { if (state == PushButtonState.Pressed) { ControlPaint.DrawButton(g, bounds, ButtonState.Pushed); } else { ControlPaint.DrawButton(g, bounds, ButtonState.Normal); } if (image != null) { g.DrawImage(image, imageBounds); } } Rectangle_ focus_rect = bounds; focus_rect.Inflate(-3, -3); if (focused) { ControlPaint.DrawFocusRectangle(g, focus_rect); } if (buttonText != String.Empty) { if (state == PushButtonState.Disabled) { TextRenderer.DrawText(g, buttonText, font, focus_rect, SystemColors.GrayText, flags); } else { TextRenderer.DrawText(g, buttonText, font, focus_rect, SystemColors.ControlText, flags); } } }
protected Rectangle_ CalcImageRenderBounds(Image image, Rectangle_ r, ContentAlignment align) { Rectangle_ rcImageClip = r; rcImageClip.Inflate(-2, -2); int X = r.X; int Y = r.Y; if (align == ContentAlignment.TopCenter || align == ContentAlignment.MiddleCenter || align == ContentAlignment.BottomCenter) { X += (r.Width - image.Width) / 2; } else if (align == ContentAlignment.TopRight || align == ContentAlignment.MiddleRight || align == ContentAlignment.BottomRight) { X += (r.Width - image.Width); } if (align == ContentAlignment.BottomCenter || align == ContentAlignment.BottomLeft || align == ContentAlignment.BottomRight) { Y += r.Height - image.Height; } else if (align == ContentAlignment.MiddleCenter || align == ContentAlignment.MiddleLeft || align == ContentAlignment.MiddleRight) { Y += (r.Height - image.Height) / 2; } rcImageClip.X = X; rcImageClip.Y = Y; rcImageClip.Width = image.Width; rcImageClip.Height = image.Height; return(rcImageClip); }
protected override int DrawTab(Graphics dc, TabPage page, TabControl tab, Rectangle_ bounds, bool is_selected) { if (!ShouldPaint(tab)) { return(base.DrawTab(dc, page, tab, bounds, is_selected)); } VisualStyleElement element = GetVisualStyleElement(tab, page, is_selected); if (!VisualStyleRenderer.IsElementDefined(element)) { return(base.DrawTab(dc, page, tab, bounds, is_selected)); } new VisualStyleRenderer(element).DrawBackground(dc, bounds); bounds.Inflate( -(tab.Padding.X), -(tab.Padding.Y)); Rectangle_ text_area = bounds; if (tab.ImageList != null && page.ImageIndex >= 0 && page.ImageIndex < tab.ImageList.Images.Count) { int image_y = bounds.Y + (bounds.Height - tab.ImageList.ImageSize.Height) / 2; tab.ImageList.Draw(dc, new Point_(bounds.X, image_y), page.ImageIndex); int image_occupied_space = tab.ImageList.ImageSize.Width + 2; text_area.X += image_occupied_space; text_area.Width -= image_occupied_space; } if (page.Text != null) { dc.DrawString(page.Text, tab.Font, SystemBrushes.ControlText, text_area, DefaultFormatting); } if (tab.Focused && is_selected && tab.ShowFocusCues) { ControlPaint.DrawFocusRectangle(dc, bounds); } return(0); }
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); }
internal override void PaintPartSelectionBackground(Graphics graphics, Rectangle_ cellBounds, DataGridViewElementStates cellState, DataGridViewCellStyle cellStyle) { cellBounds.Inflate(-2, -2); base.PaintPartSelectionBackground(graphics, cellBounds, cellState, cellStyle); }