public static Image VisualStyleRendererToImage(VisualStyleElement element, Rectangle bounds) { if (ToolStripManager.VisualStylesEnabled && VisualStyleRenderer.IsElementDefined(element)) { VisualStyleRenderer renderer = new VisualStyleRenderer(element); using (Bitmap bit = new Bitmap(bounds.Width, bounds.Height, PixelFormat.Format32bppArgb)) { NativeMethods.BITMAPINFO bmi = new NativeMethods.BITMAPINFO(); bmi.biWidth = bit.Width; bmi.biHeight = bit.Height; bmi.biPlanes = 1; bmi.biBitCount = 32; bmi.biXPelsPerMeter = (int)bit.HorizontalResolution; bmi.biYPelsPerMeter = (int)bit.VerticalResolution; bmi.biSize = Marshal.SizeOf(typeof(NativeMethods.BITMAPINFO)); IntPtr bits; IntPtr bmp = NativeMethods.CreateDIBSection(IntPtr.Zero, ref bmi, NativeMethods.DIB_RGB_COLORS, out bits, IntPtr.Zero, 0); IntPtr dc = NativeMethods.GetDC(IntPtr.Zero); IntPtr hdc = NativeMethods.CreateCompatibleDC(dc); NativeMethods.SelectObject(hdc, bmp); using (Graphics g = Graphics.FromHdc(hdc)) { renderer.DrawBackground(g, bounds); } Bitmap image = new Bitmap(bounds.Width, bounds.Height, PixelFormat.Format32bppPArgb); using (Bitmap tempImage = new Bitmap(bounds.Width, bounds.Height, bounds.Width * 4, PixelFormat.Format32bppPArgb, bits)) { BitmapData tempBitmapData = tempImage.LockBits(bounds, ImageLockMode.ReadOnly, PixelFormat.Format32bppPArgb); BitmapData bitmapData = image.LockBits(bounds, ImageLockMode.WriteOnly, PixelFormat.Format32bppPArgb); NativeMethods.CopyMemory(bitmapData.Scan0, tempBitmapData.Scan0, (uint)tempBitmapData.Stride * (uint)tempBitmapData.Height); tempImage.UnlockBits(tempBitmapData); image.UnlockBits(bitmapData); } NativeMethods.DeleteObject(bmp); NativeMethods.DeleteDC(hdc); NativeMethods.ReleaseDC(IntPtr.Zero, dc); return(image); } } else { return(new Bitmap(bounds.Width, bounds.Height)); } }
protected override void OnRenderToolStripPanelBackground(ToolStripPanelRenderEventArgs e) { //Draw the background using Rebar & RP_BACKGROUND (or, if that is not available, fall back to //Rebar.Band.Normal) if (VisualStyleRenderer.IsElementDefined(VisualStyleElement.CreateElement(RebarClass, RP_BACKGROUND, 0))) { renderer.SetParameters(RebarClass, RP_BACKGROUND, 0); } else { renderer.SetParameters(RebarClass, 0, 0); //renderer.SetParameters(VisualStyleElement.Taskbar.BackgroundBottom.Normal); //renderer.SetParameters(Subclass(VisualStyleElement.Rebar.Band.Normal)); } if (renderer.IsBackgroundPartiallyTransparent()) { renderer.DrawParentBackground(e.Graphics, e.ToolStripPanel.ClientRectangle, e.ToolStripPanel); } renderer.DrawBackground(e.Graphics, e.ToolStripPanel.ClientRectangle); //Draw the etched edges of each row. //renderer.SetParameters(Subclass(VisualStyleElement.Rebar.Band.Normal)); //foreach (ToolStripPanelRow row in e.ToolStripPanel.Rows) { // Rectangle rowBounds = row.Bounds; // rowBounds.Offset(0, -1); // renderer.DrawEdge(e.Graphics, rowBounds, Edges.Top, EdgeStyle.Etched, EdgeEffects.None); //} e.Handled = true; }
/// <summary> /// Handles the item drawing of a selected item. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.DrawItemEventArgs"/> that contains the event data.</param> /// <param name="hover">Determines whether the cursor is currently hovering over the item.</param> protected virtual void DrawItemSelected(DrawItemEventArgs e, bool hover) { if (VisualStyleRenderer.IsSupported) { VisualStyleElement elementToDraw = hover ? VisualStyleElement.CreateElement("Explorer::ListView", 1, (int)ListViewState.HotSelected) : VisualStyleElement.CreateElement("Explorer::ListView", 1, (int)ListViewState.Selected); if (VisualStyleRenderer.IsElementDefined(elementToDraw)) { new VisualStyleRenderer(elementToDraw).DrawBackground(e.Graphics, e.Bounds); return; } } using (Pen backPen = new Pen(Color.FromArgb(50, SystemColors.Highlight))) { e.Graphics.FillRectangle( backPen.Brush , 0 , e.Bounds.Top , e.Bounds.Width - 0 , e.Bounds.Height - 0); using (Pen highlightPen = new Pen(Color.FromArgb(200, backPen.Color))) { e.Graphics.DrawRectangle( highlightPen , 0 , e.Bounds.Top , e.Bounds.Width - 1 , e.Bounds.Height - 1); } } }
protected override void OnRenderMenuItemBackground(ToolStripItemRenderEventArgs e) { var rect = !e.Item.IsOnDropDown ? new Rectangle(new Point(), e.Item.Bounds.Size) : e.Item.ContentRectangle; if (e.Item.IsOnDropDown) { rect.Inflate(0, 1); } var element = VisualStyleElement.CreateElement("menu", !e.Item.IsOnDropDown ? 8 : 14, (e.Item.Enabled ? 0 : !e.Item.IsOnDropDown ? 3 : 2) + (!e.Item.Pressed || e.Item.IsOnDropDown ? !e.Item.Selected ? 1 : 2 : 3)); if (VisualStyleRenderer.IsSupported && VisualStyleRenderer.IsElementDefined(element)) { var renderer = new VisualStyleRenderer(element); if (!e.Item.IsOnDropDown) { rect.Height--; } else { rect.X++; rect.Width--; } renderer.DrawBackground(e.Graphics, rect); } else { base.OnRenderMenuItemBackground(e); } }
protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e) { if (EnsureRenderer()) { if (e.ToolStrip.IsDropDown) { renderer.SetParameters(MenuClass, 9, 0); } else { if (e.ToolStrip.Parent is ToolStripPanel) { return; } if (VisualStyleRenderer.IsElementDefined(VisualStyleElement.CreateElement(RebarClass, RebarBackground, 0))) { renderer.SetParameters(RebarClass, RebarBackground, 0); } else { renderer.SetParameters(RebarClass, 0, 0); } } if (renderer.IsBackgroundPartiallyTransparent()) { renderer.DrawParentBackground(e.Graphics, e.ToolStrip.ClientRectangle, e.ToolStrip); } renderer.DrawBackground(e.Graphics, e.ToolStrip.ClientRectangle, e.AffectedBounds); } else { base.OnRenderToolStripBackground(e); } }
// ------------------------------------------------------------------------ public TDLRenderer(IntPtr hWnd, UIExtension.TaskIcon taskIcons) { // One time initialisation if (m_SelectionRect == null) { m_SelectionRect = new UIExtension.SelectionRect(); if (VisualStyleRenderer.IsSupported) { if (VisualStyleRenderer.IsElementDefined(VisualStyleElement.Header.Item.Normal)) { m_HeaderNormal = new VisualStyleRenderer(VisualStyleElement.Header.Item.Normal); } if (VisualStyleRenderer.IsElementDefined(VisualStyleElement.Header.Item.Hot)) { m_HeaderHot = new VisualStyleRenderer(VisualStyleElement.Header.Item.Hot); } } } m_TaskIcons = taskIcons; m_hWnd = hWnd; m_ShowParentsAsFolder = false; }
static HeaderRenderer() { isSupported = VisualStyleRenderer.IsSupported && VisualStyleRenderer.IsElementDefined(VisualStyleElement.Header.Item.Normal) && VisualStyleRenderer.IsElementDefined(VisualStyleElement.Header.Item.Hot) && VisualStyleRenderer.IsElementDefined(VisualStyleElement.Header.Item.Pressed); }
private void DrawDefaults(TabControl control, DrawItemEventArgs e) { VisualStyleRenderer render = null; if (e.State == DrawItemState.Selected) { if (VisualStyleRenderer.IsElementDefined(VisualStyleElement.Tab.TabItem.Pressed)) { render = new VisualStyleRenderer(VisualStyleElement.Tab.TabItem.Pressed); } } else { if (VisualStyleRenderer.IsElementDefined(VisualStyleElement.Tab.TabItem.Normal)) { render = new VisualStyleRenderer(VisualStyleElement.Tab.TabItem.Normal); } } if (render != null) { render.DrawBackground(e.Graphics, e.Bounds); render.DrawText(e.Graphics, e.Bounds, control.TabPages[e.Index].Text, false, TextFormatFlags.SingleLine | TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter); } }
public CheckableToolStripSplitButton() { if (Application.RenderWithVisualStyles && VisualStyleRenderer.IsElementDefined(element)) { renderer = new VisualStyleRenderer(element); } }
protected override void OnRenderItemCheck(ToolStripItemImageRenderEventArgs e) { var rect = e.Item.ContentRectangle; rect.Inflate(1, 1); rect.X += 2; rect.Width = rect.Height; var element = VisualStyleElement.CreateElement("menu", 12, !e.Item.Enabled ? 1 : 2); if (VisualStyleRenderer.IsSupported && VisualStyleRenderer.IsElementDefined(element)) { var renderer = new VisualStyleRenderer(element); renderer.DrawBackground(e.Graphics, rect); } // FIXME: This should cope with radios, if we can have them. Add 2 to state. element = VisualStyleElement.CreateElement("menu", 11, e.Item.Enabled ? 1 : 2); if (VisualStyleRenderer.IsSupported && VisualStyleRenderer.IsElementDefined(element)) { var renderer = new VisualStyleRenderer(element); renderer.DrawBackground(e.Graphics, rect); } else { base.OnRenderItemCheck(e); } }
/// <summary> /// 绘制 RadioButton。 /// </summary> /// <param name="graphics"></param> /// <param name="rect"></param> /// <param name="checked"></param> /// <param name="enabled"></param> public virtual void DrawRadioButton(Graphics graphics, Rectangle rect, bool @checked, bool enabled) { if (Application.RenderWithVisualStyles) { var element = GetCheckVisualStyleElement(@checked, enabled); if (element != null && VisualStyleRenderer.IsElementDefined(element)) { new VisualStyleRenderer(element).DrawBackground(graphics, rect); return; } } var bstate = ButtonState.Flat; if (@checked) { bstate |= ButtonState.Checked; } if (!enabled) { bstate |= ButtonState.Inactive; } ControlPaint.DrawRadioButton(graphics, rect, bstate); }
public override void OnRenderGrip(ToolStripGripRenderEventArgs e) { if (!ThemeVisualStyles.RenderClientAreas) { base.OnRenderGrip(e); return; } if (e.GripStyle == ToolStripGripStyle.Hidden) { return; } VisualStyleElement element = e.GripDisplayStyle == ToolStripGripDisplayStyle.Vertical ? VisualStyleElement.Rebar.Gripper.Normal : VisualStyleElement.Rebar.GripperVertical.Normal; if (!VisualStyleRenderer.IsElementDefined(element)) { base.OnRenderGrip(e); return; } new VisualStyleRenderer(element).DrawBackground(e.Graphics, e.GripDisplayStyle == ToolStripGripDisplayStyle.Vertical ? // GetPartSize seems to return useless values. new Rectangle(2, 0, 5, 20) : new Rectangle(0, 2, 20, 5)); }
protected override void OnRenderToolStripPanelBackground(ToolStripPanelRenderEventArgs e) { if (EnsureRenderer()) { // Draw the background using Rebar & RP_BACKGROUND (or, if that is not available, fall back to // Rebar.Band.Normal) if (VisualStyleRenderer.IsElementDefined(VisualStyleElement.CreateElement(RebarClass, RebarBackground, 0))) { renderer.SetParameters(RebarClass, RebarBackground, 0); } else { renderer.SetParameters(RebarClass, 0, 0); } if (renderer.IsBackgroundPartiallyTransparent()) { renderer.DrawParentBackground(e.Graphics, e.ToolStripPanel.ClientRectangle, e.ToolStripPanel); } renderer.DrawBackground(e.Graphics, e.ToolStripPanel.ClientRectangle); e.Handled = true; } else { base.OnRenderToolStripPanelBackground(e); } }
/// <summary> /// 绘制 CheckBox。 /// </summary> /// <param name="graphics"></param> /// <param name="rect"></param> /// <param name="checked"></param> /// <param name="mixed"></param> /// <param name="enabled"></param> public virtual void DrawCheckbox(Graphics graphics, Rectangle rect, bool @checked, bool mixed, bool enabled) { if (Application.RenderWithVisualStyles) { var element = GetCheckVisualStyleElement(@checked, mixed, enabled); if (element != null && VisualStyleRenderer.IsElementDefined(element)) { new VisualStyleRenderer(element).DrawBackground(graphics, rect); return; } } var bstate = ButtonState.Flat; if (@checked) { bstate |= ButtonState.Checked; } if (!enabled) { bstate |= ButtonState.Inactive; } ControlPaint.DrawCheckBox(graphics, rect, bstate); if (mixed) { var r = rect; r.Inflate(-4, -4); graphics.FillRectangle(Brushes.LightGray, r); } }
/// <summary> /// Draw a background for the header, without using Themes. /// </summary> /// <param name="g"></param> /// <param name="r"></param> /// <param name="columnIndex"></param> /// <param name="isSelected"></param> /// <param name="stateStyle"></param> protected void DrawUnthemedBackground(Graphics g, Rectangle r, int columnIndex, bool isSelected, HeaderStateStyle stateStyle) { if (stateStyle.BackColor.IsEmpty) { // I know we're supposed to be drawing the unthemed background, but let's just see if we // can draw something more interesting than the dull raised block if (VisualStyleRenderer.IsSupported && VisualStyleRenderer.IsElementDefined(VisualStyleElement.Header.Item.Normal)) { DrawThemedBackground(g, r, columnIndex, isSelected); } else { ControlPaint.DrawBorder3D(g, r, Border3DStyle.RaisedInner); } } else { using (Brush b = new SolidBrush(stateStyle.BackColor)) g.FillRectangle(b, r); } // Draw the frame if the style asks for one if (!stateStyle.FrameColor.IsEmpty && stateStyle.FrameWidth > 0f) { RectangleF r2 = r; r2.Inflate(-stateStyle.FrameWidth, -stateStyle.FrameWidth); g.DrawRectangle(new Pen(stateStyle.FrameColor, stateStyle.FrameWidth), r2.X, r2.Y, r2.Width, r2.Height); } }
public override void OnRenderToolStripBackground(ToolStripRenderEventArgs e) { if (e.ToolStrip.BackgroundImage != null) { return; } if (!ThemeVisualStyles.RenderClientAreas) { base.OnRenderToolStripBackground(e); return; } VisualStyleElement element; if (e.ToolStrip is StatusStrip) { element = VisualStyleElement.Status.Bar.Normal; } else { element = VisualStyleElement.Rebar.Band.Normal; } if (!VisualStyleRenderer.IsElementDefined(element)) { base.OnRenderToolStripBackground(e); return; } new VisualStyleRenderer(element).DrawBackground(e.Graphics, e.ToolStrip.Bounds, e.AffectedBounds); }
/// <summary> /// /// </summary> /// <param name="dc"></param> /// <param name="cellRect"></param> /// <param name="column"></param> /// <param name="format"></param> /// <param name="isHot"></param> public virtual void DrawHeader(Graphics dc, Rectangle cellRect, TreeListColumn column, TextFormatting format, bool isHot) { if (!Application.RenderWithVisualStyles) { ControlPaint.DrawButton(dc, cellRect, ButtonState.Flat); return; } VisualStyleElement element = VisualStyleElement.Header.Item.Normal; if (isHot) { element = VisualStyleElement.Header.Item.Hot; } if (VisualStyleRenderer.IsElementDefined(element)) { VisualStyleRenderer renderer = new VisualStyleRenderer(element); renderer.DrawBackground(dc, cellRect); if (format.BackColor != Color.Transparent) { SolidBrush brush = new SolidBrush(format.BackColor); dc.FillRectangle(brush, cellRect); brush.Dispose(); } cellRect = new Rectangle(cellRect.X + format.Padding.Left, cellRect.Y + format.Padding.Top, cellRect.Width - format.Padding.Left - format.Padding.Right, cellRect.Height - format.Padding.Top - format.Padding.Bottom); //dc.DrawRectangle(Pens.Black, cellRect); Color color = format.ForeColor; TextFormatFlags flags = TextFormatFlags.EndEllipsis | format.GetFormattingFlags(); TextRenderer.DrawText(dc, column.Caption, column.Font, cellRect, color, flags); } }
void _Initialize() { _WindowFrameColor = null; _InfoColor = null; _InfoTextColor = null; if (VisualStyleRenderer.IsSupported && VisualStyleRenderer.IsElementDefined(VisualStyleElement.ToolTip.Standard.Normal)) { try { var renderer = new VisualStyleRenderer(VisualStyleElement.ToolTip.Standard.Normal); var canvasSize = new Size(7, 7); using (var bmp = new Bitmap(canvasSize.Width, canvasSize.Height)) { using (var graphics = Graphics.FromImage(bmp)) renderer.DrawBackground(graphics, new Rectangle(Point.Empty, canvasSize)); _InfoColor = bmp.GetPixel(canvasSize.Width / 2, canvasSize.Height / 2); _WindowFrameColor = bmp.GetPixel(0, canvasSize.Height / 2); } _InfoTextColor = renderer.GetColor(ColorProperty.TextColor); } catch (Exception e) { Debug.WriteLine(e.ToString()); } } }
public virtual void DrawHeader(Graphics dc, Rectangle cellRect, TreeListColumn column, TreeList.TextFormatting format, bool isHot, bool highlight) { Rectangle textRect = AdjustRectangle(cellRect, format.Padding); if (!Application.RenderWithVisualStyles) { ControlPaint.DrawButton(dc, cellRect, m_owner.ViewOptions.UserRearrangeableColumns && highlight ? ButtonState.Pushed : ButtonState.Flat); DrawHeaderText(dc, textRect, column, format); return; } VisualStyleElement element = VisualStyleElement.Header.Item.Normal; if (isHot || highlight) { element = VisualStyleElement.Header.Item.Hot; } if (VisualStyleRenderer.IsElementDefined(element)) { VisualStyleRenderer renderer = new VisualStyleRenderer(element); renderer.DrawBackground(dc, cellRect); if (format.BackColor != Color.Transparent) { SolidBrush brush = new SolidBrush(format.BackColor); dc.FillRectangle(brush, cellRect); brush.Dispose(); } //dc.DrawRectangle(Pens.Black, cellRect); DrawHeaderText(dc, textRect, column, format); } }
/// <summary> /// Draw a more-or-less pure themed header background. /// </summary> /// <param name="g"></param> /// <param name="r"></param> /// <param name="columnIndex"></param> /// <param name="isSelected"></param> protected void DrawThemedBackground(Graphics g, Rectangle r, int columnIndex, bool isSelected) { int part = 1; // normal item if (columnIndex == 0 && VisualStyleRenderer.IsElementDefined(VisualStyleElement.Header.ItemLeft.Normal)) { part = 2; // left item } if (columnIndex == ListView.Columns.Count - 1 && VisualStyleRenderer.IsElementDefined(VisualStyleElement.Header.ItemRight.Normal)) { part = 3; // right item } int state = 1; // normal state if (isSelected) { state = 3; // pressed } else if (columnIndex == ColumnIndexUnderCursor) { state = 2; // hot } var renderer = new VisualStyleRenderer("HEADER", part, state); renderer.DrawBackground(g, r); }
/// <summary> /// Inherited from <see cref="Control"/>. /// </summary> /// <param name="pea"> /// See <see cref="Control.OnPaint(PaintEventArgs)"/>. /// </param> protected override void OnPaint(PaintEventArgs pea) { Graphics g = pea.Graphics; VisualStyleRenderer renderer = null; if (Application.RenderWithVisualStyles && VisualStyleRenderer.IsElementDefined(VisualStyleElement.Tab.Pane.Normal)) { renderer = new VisualStyleRenderer(VisualStyleElement.Tab.Pane.Normal); renderer.DrawBackground(g, paneRectangle); } else { ControlPaint.DrawBorder3D(g, paneRectangle, Border3DStyle.Raised, Border3DSide.All); } if (pea.ClipRectangle.IntersectsWith(tabsRectangle)) { foreach (BpTabPage page in Controls) { if (page != selectedTab) { PaintTab(page, g); } } PaintTab(selectedTab, g); } }
protected void PaintTab(BpTabPage page, Graphics g) { Rectangle bounds = GetTabRect(page); VisualStyleElement element = GetElement(page); if (Application.RenderWithVisualStyles && VisualStyleRenderer.IsElementDefined(element)) { VisualStyleRenderer renderer = new VisualStyleRenderer(element); renderer.DrawBackground(g, bounds); bounds = renderer.GetBackgroundContentRectangle(g, bounds); } else { ControlPaint.DrawBorder3D(g, bounds, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Middle); } if (IncludesCloseButton(page)) { Rectangle closerect = GetTabCloseRect(page, bounds); element = VisualStyleElement.ToolTip.Close.Normal; Border3DStyle borderstyle = Border3DStyle.Flat; if (hoverClose) { if (clickClose == page) { element = VisualStyleElement.ToolTip.Close.Pressed; borderstyle = Border3DStyle.Sunken; } else if (clickClose == null) { element = VisualStyleElement.ToolTip.Close.Hot; borderstyle = Border3DStyle.Raised; } } if (Application.RenderWithVisualStyles && VisualStyleRenderer.IsElementDefined(element)) { VisualStyleRenderer renderer = new VisualStyleRenderer(element); renderer.DrawBackground(g, closerect); } else { if (borderstyle != Border3DStyle.Flat) { ControlPaint.DrawBorder3D(g, closerect, borderstyle); } Font closefont = new Font("Marlett", SystemFonts.MenuFont.Size); Point pos = closerect.Location; pos.X += SystemInformation.Border3DSize.Width; pos.Y += SystemInformation.Border3DSize.Height; TextRenderer.DrawText(g, "r", closefont, pos, Color.Black); } } bounds = GetTabContentRect(page, bounds); TabPaintEventArgs ea = new TabPaintEventArgs(g, bounds, page); OnTabPaint(ea); page.CallTabPaint(ea); }
/// <summary> /// Should the given column show a non-themed sort indicator? /// </summary> /// <param name="column"></param> /// <returns></returns> protected bool HasNonThemedSortIndicator(OLVColumn column) { if (!this.ListView.ShowSortIndicators) return false; if (VisualStyleRenderer.IsSupported) return !VisualStyleRenderer.IsElementDefined(VisualStyleElement.Header.SortArrow.SortedUp) && this.HasSortIndicator(column); else return this.HasSortIndicator(column); }
protected bool HasNonThemedSortIndicator(OLVColumn column) { if (VisualStyleRenderer.IsSupported) { return(!VisualStyleRenderer.IsElementDefined(VisualStyleElement.Header.SortArrow.SortedUp) && this.HasSortIndicator(column)); } return(this.HasSortIndicator(column)); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (VisualStyleRenderer.IsElementDefined(VisualStyleElement.Status.Gripper.Normal)) { VisualStyleRenderer renderer = new VisualStyleRenderer(VisualStyleElement.Status.Gripper.Normal); renderer.DrawBackground(e.Graphics, gripRect); } }
protected override void OnPaint(PaintEventArgs e) { if (VisualStyleRenderer.IsSupported && VisualStyleRenderer.IsElementDefined(VisualStyleElement.ExplorerBar.HeaderClose.Normal) && VisualStyleRenderer.IsElementDefined(VisualStyleElement.ExplorerBar.HeaderClose.Hot) && VisualStyleRenderer.IsElementDefined(VisualStyleElement.ExplorerBar.HeaderClose.Pressed)) { VisualStyleElement element; if (!this.ShowGreyed && IsMouseOver(this.ClientRectangle)) { element = IsLeftMouseButtonPressed() ? VisualStyleElement.ExplorerBar.HeaderClose.Pressed : VisualStyleElement.ExplorerBar.HeaderClose.Hot; } else { element = VisualStyleElement.ExplorerBar.HeaderClose.Normal; } VisualStyleRenderer renderer = new VisualStyleRenderer(element); Size size = renderer.GetPartSize(e.Graphics, this.ClientRectangle, ThemeSizeType.True); using (Bitmap bmp = new Bitmap(size.Width, size.Height)) { using (Graphics g = Graphics.FromImage(bmp)) { renderer.DrawBackground(g, this.ClientRectangle); } e.Graphics.DrawImage(bmp, this.ClientRectangle); } } else { const int lineWidth = 2; if (this.ShowGreyed) { ControlPaint.DrawButton(e.Graphics, this.ClientRectangle, ButtonState.Inactive); } else if (IsMouseOver(this.ClientRectangle) && IsLeftMouseButtonPressed()) { ControlPaint.DrawButton(e.Graphics, this.ClientRectangle, ButtonState.Pushed); } else { ControlPaint.DrawButton(e.Graphics, this.ClientRectangle, ButtonState.Normal); } using (Pen p = new Pen(this.ShowGreyed ? SystemBrushes.GrayText : SystemBrushes.ControlText, lineWidth)) { Rectangle crossBounds = this.ClientRectangle; crossBounds.Location += new Size(2 * lineWidth, 2 * lineWidth); crossBounds.Size -= new Size(4 * lineWidth + 1, 4 * lineWidth + 1); e.Graphics.DrawLine(p, crossBounds.Left, crossBounds.Top, crossBounds.Right, crossBounds.Bottom); e.Graphics.DrawLine(p, crossBounds.Left, crossBounds.Bottom, crossBounds.Right, crossBounds.Top); } } }
protected override void OnPaint(PaintEventArgs p) { Graphics g = p.Graphics; Rectangle rect = new Rectangle(0, 0, Width - 1, Height - 1); if (this.ReadOnly) { IsMouseOver = false; } if ((!this.Enabled) || this.ReadOnly) { g.FillRectangle(SystemBrushes.Window, rect); } if (VisualStyleInformation.IsEnabledByUser && VisualStyleInformation.IsSupportedByOS) { try { VisualStyleElement element = null; if (!this.Enabled) { element = VisualStyleElement.TextBox.TextEdit.Disabled; } else if (this.Focused) { element = VisualStyleElement.TextBox.TextEdit.Focused; } else if (IsMouseOver) { element = VisualStyleElement.TextBox.TextEdit.Hot; } else { element = VisualStyleElement.TextBox.TextEdit.Normal; } if (VisualStyleRenderer.IsElementDefined(element)) { VisualStyleRenderer renderer = new VisualStyleRenderer(element); renderer.DrawBackground(g, rect); return; } } catch { } } if (this.AllowDrawBorder) { StiControlPaint.DrawBorder(g, rect, (IsMouseOver | Focused) & HotFocus, Flat); } }
public override void OnRenderSplitButtonBackground(ToolStripItemRenderEventArgs e) { if (!ThemeVisualStyles.RenderClientAreas) { base.OnRenderSplitButtonBackground(e); return; } VisualStyleElement element, drop_down_element; if (IsDisabled(e.Item)) { element = VisualStyleElement.ToolBar.SplitButton.Disabled; drop_down_element = VisualStyleElement.ToolBar.SplitButtonDropDown.Disabled;; } else if (IsPressed(e.Item)) { element = VisualStyleElement.ToolBar.SplitButton.Pressed; drop_down_element = VisualStyleElement.ToolBar.SplitButtonDropDown.Pressed; } else if (IsChecked(e.Item)) { if (IsHot(e.Item)) { element = VisualStyleElement.ToolBar.SplitButton.HotChecked; drop_down_element = VisualStyleElement.ToolBar.SplitButtonDropDown.HotChecked; } else { element = VisualStyleElement.ToolBar.Button.Checked; drop_down_element = VisualStyleElement.ToolBar.SplitButtonDropDown.Checked; } } else if (IsHot(e.Item)) { element = VisualStyleElement.ToolBar.SplitButton.Hot; drop_down_element = VisualStyleElement.ToolBar.SplitButtonDropDown.Hot; } else { element = VisualStyleElement.ToolBar.SplitButton.Normal; drop_down_element = VisualStyleElement.ToolBar.SplitButtonDropDown.Normal; } if (!VisualStyleRenderer.IsElementDefined(element) || !VisualStyleRenderer.IsElementDefined(drop_down_element)) { base.OnRenderSplitButtonBackground(e); return; } ToolStripSplitButton tool_strip_split_button = (ToolStripSplitButton)e.Item; VisualStyleRenderer renderer = new VisualStyleRenderer(element); renderer.DrawBackground(e.Graphics, tool_strip_split_button.ButtonBounds); renderer.SetParameters(drop_down_element); renderer.DrawBackground(e.Graphics, tool_strip_split_button.DropDownButtonBounds); }
/// <summary> /// Draw one cell of the header /// </summary> /// <param name="g"></param> /// <param name="columnIndex"></param> /// <param name="itemState"></param> protected void CustomDrawHeaderCell(Graphics g, int columnIndex, int itemState) { Rectangle r = GetItemRect(columnIndex); OLVColumn column = ListView.GetColumn(columnIndex); const int CDIS_SELECTED = 1; bool isPressed = ((itemState & CDIS_SELECTED) == CDIS_SELECTED); // Calculate which style should be used for the header HeaderStateStyle stateStyle = CalculateStyle(column, columnIndex == ColumnIndexUnderCursor, isPressed); // If there is an owner drawn delegate installed, give it a chance to draw the header if (column.HeaderDrawing != null) { if (!column.HeaderDrawing(g, r, columnIndex, column, isPressed, stateStyle)) { return; } } // Draw the background if (ListView.HeaderUsesThemes && VisualStyleRenderer.IsSupported && VisualStyleRenderer.IsElementDefined(VisualStyleElement.Header.Item.Normal)) { DrawThemedBackground(g, r, columnIndex, isPressed); } else { DrawUnthemedBackground(g, r, columnIndex, isPressed, stateStyle); } // Draw the sort indicator if this column has one if (HasSortIndicator(column)) { if (ListView.HeaderUsesThemes && VisualStyleRenderer.IsSupported && VisualStyleRenderer.IsElementDefined(VisualStyleElement.Header.SortArrow.SortedUp)) { DrawThemedSortIndicator(g, r); } else { r = DrawUnthemedSortIndicator(g, r); } } if (HasFilterIndicator(column)) { r = DrawFilterIndicator(g, r); } // Finally draw the text DrawHeaderImageAndText(g, r, column, stateStyle); }
public static Color GetColor(VisualStyleElement element, ColorProperty colorProperty, Color defaultColor) { if (VisualStyleRenderer.IsSupported && VisualStyleRenderer.IsElementDefined(element)) { return(new VisualStyleRenderer(element).GetColor(colorProperty)); } else { return(defaultColor); } }