public void VisualStyleRenderer_DrawImage_NullG_ThrowsArgumentNullException() { var renderer = new VisualStyleRenderer(VisualStyleElement.Button.PushButton.Normal); using var image = new Bitmap(10, 10); Assert.Throws <ArgumentNullException>("g", () => renderer.DrawImage(null, new Rectangle(1, 2, 3, 4), image)); Assert.Throws <ArgumentNullException>("g", () => renderer.DrawImage(null, new Rectangle(1, 2, 3, 4), new ImageList(), 0)); }
public static void DrawTabItem(Graphics g, Rectangle bounds, Image image, Rectangle imageRectangle, bool focused, TabItemState state) { InitializeRenderer(VisualStyleElement.Tab.TabItem.Normal, (int)state); visualStyleRenderer.DrawBackground(g, bounds); Rectangle rectangle = Rectangle.Inflate(bounds, -3, -3); visualStyleRenderer.DrawImage(g, imageRectangle, image); if (focused) { ControlPaint.DrawFocusRectangle(g, rectangle); } }
public static void DrawHeader(Graphics g, Rectangle bounds, Image image, Rectangle imageBounds, HeaderItemState state) { if (RenderWithVisualStyles) { InitializeRenderer((int)state); visualStyleRenderer.DrawBackground(g, bounds); visualStyleRenderer.DrawImage(g, imageBounds, image); } else { ControlPaint.DrawButton(g, bounds, ConvertToButtonState(state)); g.DrawImage(image, imageBounds); } }
/// <summary> /// <para> /// Renders a Tab item. /// </para> /// </summary> public static void DrawTabItem(Graphics g, Rectangle bounds, Image image, Rectangle imageRectangle, bool focused, TabItemState state) { InitializeRenderer(VisualStyleElement.Tab.TabItem.Normal, (int)state); visualStyleRenderer.DrawBackground(g, bounds); // GetBackgroundContentRectangle() returns same rectangle as bounds for this control! Rectangle contentBounds = Rectangle.Inflate(bounds, -3, -3); visualStyleRenderer.DrawImage(g, imageRectangle, image); if (focused) { ControlPaint.DrawFocusRectangle(g, contentBounds); } }
public static void DrawCheckBox(Graphics g, Point glyphLocation, Rectangle textBounds, string checkBoxText, Font font, TextFormatFlags flags, Image image, Rectangle imageBounds, bool focused, CheckBoxState state) { Color controlText; Rectangle bounds = new Rectangle(glyphLocation, GetGlyphSize(g, state)); if (RenderWithVisualStyles) { InitializeRenderer((int)state); visualStyleRenderer.DrawImage(g, imageBounds, image); visualStyleRenderer.DrawBackground(g, bounds); controlText = visualStyleRenderer.GetColor(ColorProperty.TextColor); } else { g.DrawImage(image, imageBounds); if (IsMixed(state)) { ControlPaint.DrawMixedCheckBox(g, bounds, ConvertToButtonState(state)); } else { ControlPaint.DrawCheckBox(g, bounds, ConvertToButtonState(state)); } controlText = SystemColors.ControlText; } TextRenderer.DrawText(g, checkBoxText, font, textBounds, controlText, flags); if (focused) { ControlPaint.DrawFocusRectangle(g, textBounds); } }
internal static void DrawRadioButton(Graphics g, Point glyphLocation, Rectangle textBounds, string radioButtonText, Font font, TextFormatFlags flags, Image image, Rectangle imageBounds, bool focused, RadioButtonState state, IntPtr hWnd) { Rectangle glyphBounds = new Rectangle(glyphLocation, GetGlyphSize(g, state, hWnd)); Color textColor; if (RenderWithVisualStyles) { InitializeRenderer((int)state); //Keep this drawing order! It matches default drawing order. visualStyleRenderer.DrawImage(g, imageBounds, image); visualStyleRenderer.DrawBackground(g, glyphBounds); textColor = visualStyleRenderer.GetColor(ColorProperty.TextColor); } else { g.DrawImage(image, imageBounds); ControlPaint.DrawRadioButton(g, glyphBounds, ConvertToButtonState(state)); textColor = SystemColors.ControlText; } TextRenderer.DrawText(g, radioButtonText, font, textBounds, textColor, flags); if (focused) { ControlPaint.DrawFocusRectangle(g, textBounds); } }
public void VisualStyleRenderer_DrawImage_NullImageList_ThrowsArgumentNullException() { var renderer = new VisualStyleRenderer(VisualStyleElement.Button.PushButton.Normal); using var image = new Bitmap(10, 10); using var bitmap = new Bitmap(10, 10); using Graphics graphics = Graphics.FromImage(bitmap); Assert.Throws <ArgumentNullException>("imageList", () => renderer.DrawImage(graphics, new Rectangle(1, 2, 3, 4), null, 0)); }
public void VisualStyleRenderer_DrawImage_InvalidImageIndex_ThrowsArgumentNullException(int imageIndex) { var renderer = new VisualStyleRenderer(VisualStyleElement.Button.PushButton.Normal); using var bitmap = new Bitmap(10, 10); using Graphics graphics = Graphics.FromImage(bitmap); using var image = new Bitmap(10, 10); using var imageList = new ImageList(); imageList.Images.Add(image); Assert.Throws <ArgumentOutOfRangeException>("imageIndex", () => renderer.DrawImage(graphics, new Rectangle(1, 2, 3, 4), imageList, imageIndex)); }
public void VisualStyleRenderer_DrawImage_InvokeIDeviceContextRectangleImage_Success(Rectangle bounds) { // Don't verify anything, just make sure the interop call succeeds. var renderer = new VisualStyleRenderer(VisualStyleElement.Button.PushButton.Normal); using var bitmap = new Bitmap(10, 10); using Graphics graphics = Graphics.FromImage(bitmap); using var image = new Bitmap(10, 10); renderer.DrawImage(graphics, bounds, image); Assert.Equal(0, renderer.LastHResult); }
public static void DrawButton(Graphics g, Rectangle bounds, Image image, Rectangle imageBounds, bool focused, PushButtonState state) { Rectangle backgroundContentRectangle; if (RenderWithVisualStyles) { InitializeRenderer((int)state); visualStyleRenderer.DrawBackground(g, bounds); visualStyleRenderer.DrawImage(g, imageBounds, image); backgroundContentRectangle = visualStyleRenderer.GetBackgroundContentRectangle(g, bounds); } else { ControlPaint.DrawButton(g, bounds, ConvertToButtonState(state)); g.DrawImage(image, imageBounds); backgroundContentRectangle = Rectangle.Inflate(bounds, -3, -3); } if (focused) { ControlPaint.DrawFocusRectangle(g, backgroundContentRectangle); } }
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); } } }
public static void DrawTabItem(Graphics g, Rectangle bounds, string tabItemText, Font font, TextFormatFlags flags, Image image, Rectangle imageRectangle, bool focused, TabItemState state) { if (!IsSupported) { throw new InvalidOperationException(); } VisualStyleRenderer vsr; switch (state) { case TabItemState.Disabled: vsr = new VisualStyleRenderer(VisualStyleElement.Tab.TabItem.Disabled); break; case TabItemState.Hot: vsr = new VisualStyleRenderer(VisualStyleElement.Tab.TabItem.Hot); break; case TabItemState.Normal: default: vsr = new VisualStyleRenderer(VisualStyleElement.Tab.TabItem.Normal); break; case TabItemState.Selected: vsr = new VisualStyleRenderer(VisualStyleElement.Tab.TabItem.Pressed); break; } vsr.DrawBackground(g, bounds); if (image != null) { vsr.DrawImage(g, imageRectangle, image); } bounds.Offset(3, 3); bounds.Height -= 6; bounds.Width -= 6; if (tabItemText != String.Empty) { TextRenderer.DrawText(g, tabItemText, font, bounds, SystemColors.ControlText, flags); } if (focused) { ControlPaint.DrawFocusRectangle(g, bounds); } }
protected override void OnPaint(PaintEventArgs e) { #if AdvancedLogging try { Log.Logger.EnterMethod(this, "OnPaint(PaintEventArgs e)"); #endif if(_Checked) { if(renderer != null) { Rectangle cr = base.ContentRectangle; Image img = Image; // Compute the center of the item's ContentRectangle. var centerY = (int)((cr.Height - img.Height * Environment.Dpi / 96) / 2); var fullRect = new Rectangle(0, 0, Width, Height); var imageRect = new Rectangle( ContentRectangle.Left, ContentRectangle.Top + (int)(centerY * Environment.Dpi / 96), (int)(base.Image.Width * Environment.Dpi / 96), (int)(base.Image.Height * Environment.Dpi / 96)); var textRect = new Rectangle( ContentRectangle.Left + (int)(imageRect.Width * Environment.Dpi / 96), ContentRectangle.Top, ContentRectangle.Width - (int)((imageRect.Width + 10) * Environment.Dpi / 96), ContentRectangle.Height); renderer.DrawBackground(e.Graphics, fullRect); renderer.DrawText(e.Graphics, textRect, Text); renderer.DrawImage(e.Graphics, imageRect, Image); } else { base.OnPaint(e); e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(40, SystemColors.Control)), 0, 0, Width, Height); e.Graphics.DrawLines(SystemPens.ControlDark, new[] { new Point(0, ButtonBounds.Height), new Point(0, 0), new Point(ButtonBounds.Width, 0) }); e.Graphics.DrawLines(SystemPens.ControlLight, new[] { new Point(ButtonBounds.Width, 0), new Point(ButtonBounds.Width, ButtonBounds.Height), new Point(0, ButtonBounds.Height) }); } } else { base.OnPaint(e); } #if AdvancedLogging } finally { Log.Logger.LeaveMethod(this, "OnPaint(PaintEventArgs e)"); } #endif }
public static void DrawCheckBox(Graphics g, Point_ glyphLocation, Rectangle_ textBounds, string checkBoxText, Font font, TextFormatFlags flags, Image image, Rectangle_ imageBounds, bool focused, CheckBoxState state) { Rectangle_ bounds = new Rectangle_(glyphLocation, GetGlyphSize(g, state)); if (Application.RenderWithVisualStyles || always_use_visual_styles == true) { VisualStyleRenderer vsr = GetCheckBoxRenderer(state); vsr.DrawBackground(g, bounds); if (image != null) { vsr.DrawImage(g, imageBounds, image); } if (focused) { ControlPaint.DrawFocusRectangle(g, textBounds); } if (checkBoxText != String.Empty) { if (state == CheckBoxState.CheckedDisabled || state == CheckBoxState.MixedDisabled || state == CheckBoxState.UncheckedDisabled) { TextRenderer.DrawText(g, checkBoxText, font, textBounds, SystemColors.GrayText, flags); } else { TextRenderer.DrawText(g, checkBoxText, font, textBounds, SystemColors.ControlText, flags); } } } else { switch (state) { case CheckBoxState.CheckedDisabled: case CheckBoxState.MixedDisabled: case CheckBoxState.MixedPressed: ControlPaint.DrawCheckBox(g, bounds, ButtonState.Inactive | ButtonState.Checked); break; case CheckBoxState.CheckedHot: case CheckBoxState.CheckedNormal: ControlPaint.DrawCheckBox(g, bounds, ButtonState.Checked); break; case CheckBoxState.CheckedPressed: ControlPaint.DrawCheckBox(g, bounds, ButtonState.Pushed | ButtonState.Checked); break; case CheckBoxState.MixedHot: case CheckBoxState.MixedNormal: ControlPaint.DrawMixedCheckBox(g, bounds, ButtonState.Checked); break; case CheckBoxState.UncheckedDisabled: case CheckBoxState.UncheckedPressed: ControlPaint.DrawCheckBox(g, bounds, ButtonState.Inactive); break; case CheckBoxState.UncheckedHot: case CheckBoxState.UncheckedNormal: ControlPaint.DrawCheckBox(g, bounds, ButtonState.Normal); break; } if (image != null) { g.DrawImage(image, imageBounds); } if (focused) { ControlPaint.DrawFocusRectangle(g, textBounds); } if (checkBoxText != String.Empty) { TextRenderer.DrawText(g, checkBoxText, font, textBounds, SystemColors.ControlText, flags); } } }
public override void DrawImage(Graphics graphics, Rectangle bounds, Image image) { _renderer.DrawImage(graphics, bounds, image); }
protected virtual void PaintButtons(Graphics g, Rectangle buttonRect, Image bmp, bool isPressed, bool isMouseOverButton) { if (VisualStyleInformation.IsEnabledByUser && VisualStyleInformation.IsSupportedByOS) { buttonRect.Inflate(1, 1); buttonRect.X += 1; buttonRect.Width -= 1; VisualStyleElement element = null; if (DesignMode) { element = VisualStyleElement.ComboBox.DropDownButton.Normal; } else if (isPressed) { element = VisualStyleElement.ComboBox.DropDownButton.Pressed; } else if (!Enabled) { element = VisualStyleElement.ComboBox.DropDownButton.Disabled; } else { element = VisualStyleElement.ComboBox.DropDownButton.Normal; } try { if (VisualStyleRenderer.IsElementDefined(element)) { //if (bmp != null) { element = VisualStyleElement.Button.PushButton.Normal; if (DesignMode) { element = VisualStyleElement.Button.PushButton.Normal; } else if (isPressed) { element = VisualStyleElement.Button.PushButton.Pressed; } //else if (IsMouseOver) element = VisualStyleElement.Button.PushButton.Hot; else if (!Enabled) { element = VisualStyleElement.Button.PushButton.Disabled; } else { element = VisualStyleElement.Button.PushButton.Normal; } if (VisualStyleRenderer.IsElementDefined(element)) { buttonRect.Inflate(1, 1); VisualStyleRenderer renderer = new VisualStyleRenderer(element); renderer.DrawBackground(g, buttonRect); if (bmp == null) { bmp = dropDownButtonBitmap; } Rectangle imageRect = new Rectangle( buttonRect.X + (buttonRect.Width - bmp.Width) / 2 + 1, buttonRect.Y + (buttonRect.Height - bmp.Height) / 2 + 1, bmp.Width, bmp.Height); renderer.DrawImage(g, imageRect, bmp); return; } } /* * else * { * if (DesignMode) element = VisualStyleElement.ComboBox.DropDownButton.Normal; * else if (isPressed) element = VisualStyleElement.ComboBox.DropDownButton.Pressed; * //else if (IsMouseOver) element = VisualStyleElement.ComboBox.DropDownButton.Hot; * else if (!Enabled) element = VisualStyleElement.ComboBox.DropDownButton.Disabled; * else element = VisualStyleElement.ComboBox.DropDownButton.Normal; * * if (VisualStyleRenderer.IsElementDefined(element)) * { * VisualStyleRenderer renderer = new VisualStyleRenderer(element); * renderer.DrawBackground(g, buttonRect); * } * }*/ } } catch { } } else { StiControlPaint.DrawButton(g, buttonRect, bmp, isPressed, Focused | IsMouseOver, isMouseOverButton, this.Enabled, Flat); if (ButtonBitmap == null) { Rectangle imageRect = new Rectangle( buttonRect.X + (buttonRect.Width - dropDownButtonBitmap.Width) / 2, buttonRect.Y + (buttonRect.Height - dropDownButtonBitmap.Height) / 2, dropDownButtonBitmap.Width, dropDownButtonBitmap.Height); g.DrawImage(dropDownButtonBitmap, imageRect); } } }
/// <summary> /// Raises the Paint event. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs" /> that contains the event data.</param> protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); try { // Setup variables var useVs = rnd != null && Application.RenderWithVisualStyles; var r = DeflateRect(ClientRectangle, Padding); var tff = this.BuildTextFormatFlags(); Rectangle tRect, iRect; ExtensionMethods.CalcImageAndTextBounds(r, Text, Font, Image, TextAlign, ImageAlign, TextImageRelation, !AutoSize, 0, ref tff, out tRect, out iRect); // Draw background if (SupportGlass && !this.IsDesignMode() && DesktopWindowManager.IsCompositionEnabled()) { e.Graphics.Clear(Color.Black); } else { if (useVs) { rnd.DrawBackground(e.Graphics, ClientRectangle, e.ClipRectangle); } else { e.Graphics.Clear(BackColor); } } // Draw image if (Image != null) { if (useVs) { rnd.DrawImage(e.Graphics, iRect, Image); } else { e.Graphics.DrawImage(Image, iRect); } } // Draw text if (Text.Length > 0) { var rtl = this.GetRightToLeftProperty(); if (useVs) { if (rtl == RightToLeft.Yes) { tff |= TextFormatFlags.RightToLeft; } if (GlowingText) { rnd.DrawGlowingText(e.Graphics, tRect, Text, Font, ForeColor, tff); } else { rnd.DrawText(e.Graphics, tRect, Text, !Enabled, tff); } } else { var br = DesktopWindowManager.IsCompositionEnabled() ? SystemBrushes.ActiveCaptionText : SystemBrushes.ControlText; var sf = new StringFormat(StringFormat.GenericDefault); if (rtl == RightToLeft.Yes) { sf.FormatFlags |= StringFormatFlags.DirectionRightToLeft; } e.Graphics.DrawString(Text, Font, br, ClientRectangle, sf); } } } catch { } }