From c2dc64a328c1cbbd63c92fcd992cf77f14deb799 Mon Sep 17 00:00:00 2001 From: David Hall Date: Wed, 27 Jun 2018 13:12:28 -0600 Subject: [PATCH] Minor bug fixes on rendering --- WIndows.Forms/Controls/ThemedPanel.cs | 42 ++++++++++++++++++++---- WIndows.Forms/Controls/ThemedTableLayoutPanel.cs | 25 +++++++++++--- 2 files changed, 56 insertions(+), 11 deletions(-) diff --git a/WIndows.Forms/Controls/ThemedPanel.cs b/WIndows.Forms/Controls/ThemedPanel.cs index 840bee40..923958af 100644 --- a/WIndows.Forms/Controls/ThemedPanel.cs +++ b/WIndows.Forms/Controls/ThemedPanel.cs @@ -6,7 +6,7 @@ using Vanara.Extensions; namespace Vanara.Windows.Forms { - /// A panel that supports a glass overlay. + /// A panel that supports a glass overlay and is drawn using a visual style. [ToolboxItem(true), ToolboxBitmap(typeof(ThemedPanel), "ThemedPanel.bmp")] public class ThemedPanel : Panel { @@ -26,7 +26,8 @@ namespace Vanara.Windows.Forms [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public VisualStyleRenderer Style { - get => rnd; set + get => rnd; + set { rnd = value; styleClass = rnd.Class; @@ -41,7 +42,8 @@ namespace Vanara.Windows.Forms [DefaultValue("WINDOW"), Category("Appearance")] public string StyleClass { - get => styleClass; set { styleClass = value; ResetTheme(); Invalidate(); } + get => styleClass; + set { styleClass = value; ResetTheme(); } } /// Gets or sets the style part. @@ -49,7 +51,8 @@ namespace Vanara.Windows.Forms [DefaultValue(29), Category("Appearance")] public int StylePart { - get => stylePart; set { stylePart = value; ResetTheme(); Invalidate(); } + get => stylePart; + set { stylePart = value; ResetTheme(); } } /// Gets or sets the style part. @@ -57,7 +60,8 @@ namespace Vanara.Windows.Forms [DefaultValue(1), Category("Appearance")] public int StyleState { - get => styleState; set { styleState = value; ResetTheme(); Invalidate(); } + get => styleState; + set { styleState = value; ResetTheme(); } } /// Gets or sets a value indicating whether this table supports glass (can be enclosed in the glass margin). @@ -65,7 +69,8 @@ namespace Vanara.Windows.Forms [DefaultValue(false), Category("Appearance")] public bool SupportGlass { - get => supportGlass; set { supportGlass = value; Invalidate(); } + get => supportGlass; + set { supportGlass = value; Invalidate(); } } /// Sets the theme using theme class information. @@ -80,6 +85,8 @@ namespace Vanara.Windows.Forms ResetTheme(); } + /// Raises the event. + /// A that contains the event data. protected override void OnPaint(PaintEventArgs e) { if (!this.IsDesignMode() && SupportGlass && DesktopWindowManager.CompositionEnabled) @@ -87,16 +94,36 @@ namespace Vanara.Windows.Forms else { if (rnd == null || !Application.RenderWithVisualStyles) + { try { e.Graphics.Clear(BackColor); } catch { } + if (!string.IsNullOrEmpty(Text)) + TextRenderer.DrawText(e.Graphics, Text, Font, ClientRectangle, ForeColor, this.BuildTextFormatFlags(false)); + } else + { + if (rnd.IsBackgroundPartiallyTransparent()) + rnd.DrawParentBackground(e.Graphics, ClientRectangle, this); rnd.DrawBackground(e.Graphics, ClientRectangle, e.ClipRectangle); + if (!string.IsNullOrEmpty(Text)) + rnd.DrawText(e.Graphics, ClientRectangle, Text, !Enabled, this.BuildTextFormatFlags(false)); + } } base.OnPaint(e); } + /// + /// Fires the event indicating that the panel has been resized. Inheriting controls should use this in favor of actually listening to the event, but should still call base.onResize to ensure that the event is fired for external listeners. + /// + /// An that contains the event data. + protected override void OnResize(System.EventArgs eventargs) + { + base.OnResize(eventargs); + Refresh(); + } + private void ResetTheme() { - if (VisualStyleRenderer.IsSupported) + if (VisualStyleRenderer.IsSupported && styleClass != null) { try { @@ -112,6 +139,7 @@ namespace Vanara.Windows.Forms } else rnd = null; + Invalidate(); } } } \ No newline at end of file diff --git a/WIndows.Forms/Controls/ThemedTableLayoutPanel.cs b/WIndows.Forms/Controls/ThemedTableLayoutPanel.cs index efa307a6..2781cb09 100644 --- a/WIndows.Forms/Controls/ThemedTableLayoutPanel.cs +++ b/WIndows.Forms/Controls/ThemedTableLayoutPanel.cs @@ -31,7 +31,7 @@ namespace Vanara.Windows.Forms [DefaultValue("WINDOW"), Category("Appearance")] public string StyleClass { - get => styleClass; set { styleClass = value; ResetTheme(); Invalidate(); } + get => styleClass; set { styleClass = value; ResetTheme(); } } /// Gets or sets the style part. @@ -39,7 +39,7 @@ namespace Vanara.Windows.Forms [DefaultValue(29), Category("Appearance")] public int StylePart { - get => stylePart; set { stylePart = value; ResetTheme(); Invalidate(); } + get => stylePart; set { stylePart = value; ResetTheme(); } } /// Gets or sets the style part. @@ -47,7 +47,7 @@ namespace Vanara.Windows.Forms [DefaultValue(1), Category("Appearance")] public int StyleState { - get => styleState; set { styleState = value; ResetTheme(); Invalidate(); } + get => styleState; set { styleState = value; ResetTheme(); } } /// Gets or sets a value indicating whether this table supports glass (can be enclosed in the glass margin). @@ -83,16 +83,32 @@ namespace Vanara.Windows.Forms else { if (rnd == null || !Application.RenderWithVisualStyles) + { try { e.Graphics.Clear(BackColor); } catch { } + } else + { + if (rnd.IsBackgroundPartiallyTransparent()) + rnd.DrawParentBackground(e.Graphics, ClientRectangle, this); rnd.DrawBackground(e.Graphics, ClientRectangle, e.ClipRectangle); + } } base.OnPaint(e); } + /// + /// Fires the event indicating that the panel has been resized. Inheriting controls should use this in favor of actually listening to the event, but should still call base.onResize to ensure that the event is fired for external listeners. + /// + /// An that contains the event data. + protected override void OnResize(System.EventArgs eventargs) + { + base.OnResize(eventargs); + Refresh(); + } + private void ResetTheme() { - if (VisualStyleRenderer.IsSupported) + if (VisualStyleRenderer.IsSupported && styleClass != null) { try { @@ -108,6 +124,7 @@ namespace Vanara.Windows.Forms } else rnd = null; + Invalidate(); } } } \ No newline at end of file