From 195c4a33bc2f73b360ed99cf363acd5496fbe336 Mon Sep 17 00:00:00 2001 From: MTeschke Date: Fri, 27 Sep 2013 00:27:24 +0200 Subject: [PATCH 1/2] Missing File --- .../MetroRadioButtonDesigner.cs | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 MetroFramework.Design/MetroRadioButtonDesigner.cs diff --git a/MetroFramework.Design/MetroRadioButtonDesigner.cs b/MetroFramework.Design/MetroRadioButtonDesigner.cs new file mode 100644 index 00000000..da6a064f --- /dev/null +++ b/MetroFramework.Design/MetroRadioButtonDesigner.cs @@ -0,0 +1,55 @@ +/** + * MetroFramework - Modern UI for WinForms + * + * The MIT License (MIT) + * Copyright (c) 2011 Sven Walter, http://github.com/viperneo + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in the + * Software without restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, subject to the + * following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +using System.Collections; +using System.ComponentModel; +using System.Windows.Forms.Design; + +namespace MetroFramework.Design.Controls +{ + internal class MetroRadioButtonDesigner : ControlDesigner + { + protected override void PreFilterProperties(IDictionary properties) + { + properties.Remove("ImeMode"); + properties.Remove("Padding"); + properties.Remove("FlatAppearance"); + properties.Remove("FlatStyle"); + + properties.Remove("UseCompatibleTextRendering"); + properties.Remove("Image"); + properties.Remove("ImageAlign"); + properties.Remove("ImageIndex"); + properties.Remove("ImageKey"); + properties.Remove("ImageList"); + properties.Remove("TextImageRelation"); + + properties.Remove("UseVisualStyleBackColor"); + + properties.Remove("Font"); + properties.Remove("RightToLeft"); + + base.PreFilterProperties(properties); + } + } +} From b07f32b8f27f19604a5da9b6379e7846215f4f5a Mon Sep 17 00:00:00 2001 From: meese Date: Fri, 8 Nov 2013 20:17:35 -0700 Subject: [PATCH 2/2] fixes tabcontrol header rect for non default font IE change fontsize to large and it bugs out --- MetroFramework/Controls/MetroTabControl.cs | 68 +++++++++++++++------- 1 file changed, 47 insertions(+), 21 deletions(-) diff --git a/MetroFramework/Controls/MetroTabControl.cs b/MetroFramework/Controls/MetroTabControl.cs index 9a03c86e..49c90887 100644 --- a/MetroFramework/Controls/MetroTabControl.cs +++ b/MetroFramework/Controls/MetroTabControl.cs @@ -1,4 +1,4 @@ -#region Copyright (c) 2013 Jens Thiel, http://thielj.github.io/MetroFramework +#region Copyright (c) 2013 Jens Thiel, http://thielj.github.io/MetroFramework /* MetroFramework - Windows Modern UI for .NET WinForms applications @@ -40,6 +40,7 @@ Portions of this software are (c) 2011 Sven Walter, http://github.com/viperneo using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Design; +using System.Runtime.InteropServices; using System.Security; using System.Security.Permissions; using System.Windows.Forms; @@ -56,7 +57,8 @@ namespace MetroFramework.Controls [Editor("MetroFramework.Design.MetroTabPageCollectionEditor, " + AssemblyRef.MetroFrameworkDesignSN, typeof(UITypeEditor))] public class MetroTabPageCollection : TabControl.TabPageCollection { - public MetroTabPageCollection(MetroTabControl owner) : base(owner) + public MetroTabPageCollection(MetroTabControl owner) + : base(owner) { } } @@ -73,7 +75,7 @@ public partial class MetroTabControl : MetroTabControlBase private bool bUpDown = false; private const int TAB_BOTTOM_BORDER_HEIGHT = 3; - + private ContentAlignment textAlign = ContentAlignment.MiddleLeft; [DefaultValue(ContentAlignment.MiddleLeft)] [Category(MetroDefaults.CatAppearance)] @@ -112,8 +114,8 @@ public ContentAlignment TextAlign public MetroTabControl() { SetStyle(ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer, true); - // ControlStyles.AllPaintingInWmPaint | - // ControlStyles.ResizeRedraw | + // ControlStyles.AllPaintingInWmPaint | + // ControlStyles.ResizeRedraw | UseStyleColor(); UseFontStyle(); //Padding = new Point(6, 8); @@ -130,7 +132,7 @@ protected override void OnPaintBackground(PaintEventArgs e) { try { - if (TabPages == null || TabPages.Count == 0 || !(TabPages[SelectedIndex] is MetroTabPage)) + if (TabPages == null || TabPages.Count == 0 || !(TabPages[SelectedIndex] is MetroTabPage)) { e.Graphics.Clear(EffectiveBackColor); return; @@ -171,9 +173,9 @@ protected override void OnPaintForeground(PaintEventArgs e) private void DrawTabBottomBorder(int index, Graphics graphics) { - using (Brush bgBrush = new SolidBrush( GetThemeColor("BorderColor"))) + using (Brush bgBrush = new SolidBrush(GetThemeColor("BorderColor"))) { - Rectangle borderRectangle = new Rectangle(DisplayRectangle.X, GetTabRect(index).Bottom + 2 - TAB_BOTTOM_BORDER_HEIGHT, + Rectangle borderRectangle = new Rectangle(DisplayRectangle.X, GetTabRect(index).Bottom + 2 - TAB_BOTTOM_BORDER_HEIGHT, DisplayRectangle.Width, TAB_BOTTOM_BORDER_HEIGHT); graphics.FillRectangle(bgBrush, borderRectangle); @@ -188,8 +190,8 @@ private void DrawTabSelected(int index, Graphics graphics) //Size textAreaRect = MeasureText(TabPages[index].Text); Rectangle borderRectangle = new Rectangle( selectedTabRect.X + ((index == 0) ? 2 : 0), - selectedTabRect.Bottom + 2 - TAB_BOTTOM_BORDER_HEIGHT, - selectedTabRect.Width + ((index == 0) ? 0 : 2), + selectedTabRect.Bottom + 2 - TAB_BOTTOM_BORDER_HEIGHT, + selectedTabRect.Width + ((index == 0) ? 0 : 2), TAB_BOTTOM_BORDER_HEIGHT); graphics.FillRectangle(selectionBrush, borderRectangle); } @@ -243,7 +245,7 @@ private void DrawUpDown(Graphics graphics) using (Brush b = new SolidBrush(GetThemeColor("BorderColor"))) using (GraphicsPath gp = new GraphicsPath(FillMode.Winding)) { - PointF[] pts = {new PointF(6, 6), new PointF(16, 0), new PointF(16, 12)}; + PointF[] pts = { new PointF(6, 6), new PointF(16, 0), new PointF(16, 12) }; gp.AddLines(pts); graphics.FillPath(b, gp); @@ -303,7 +305,7 @@ protected override CreateParams CreateParams private new Rectangle GetTabRect(int index) { - return index < 0 ? new Rectangle() : base.GetTabRect(index); + return index < 0 ? new Rectangle() : base.GetTabRect(index); } protected override void OnMouseWheel(MouseEventArgs e) @@ -329,12 +331,16 @@ protected override void OnMouseWheel(MouseEventArgs e) } } } - + base.OnMouseWheel(e); } #endregion + + + + // The below is possibly (c) Oscar Londono // http://www.codeproject.com/Articles/12185/A-NET-Flat-TabControl-CustomDraw @@ -343,26 +349,27 @@ protected override void OnMouseWheel(MouseEventArgs e) protected override void OnCreateControl() { base.OnCreateControl(); + this.OnFontChanged(EventArgs.Empty); FindUpDown(); } protected override void OnControlAdded(ControlEventArgs e) { - base.OnControlAdded(e); - FindUpDown(); - UpdateUpDown(); + base.OnControlAdded(e); + FindUpDown(); + UpdateUpDown(); } protected override void OnControlRemoved(ControlEventArgs e) { - base.OnControlRemoved(e); + base.OnControlRemoved(e); FindUpDown(); UpdateUpDown(); } - protected override void OnSelectedIndexChanged(EventArgs e) + protected override void OnSelectedIndexChanged(EventArgs e) { - base.OnSelectedIndexChanged(e); + base.OnSelectedIndexChanged(e); UpdateUpDown(); //Invalidate(); } @@ -421,7 +428,7 @@ private int scUpDown_SubClassedWndProc(ref Message m) using (Graphics g = Graphics.FromHdc(hDC)) DrawUpDown(g); } - finally + finally { WinApi.ReleaseDC(scUpDown.Handle, hDC); } @@ -435,6 +442,25 @@ private int scUpDown_SubClassedWndProc(ref Message m) return 0; } + + //send font change to properly resize tab page header rects + //http://www.codeproject.com/Articles/13305/Painting-Your-Own-Tabs?msg=2707590#xx2707590xx + [DllImport("user32.dll")] + private static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam); + + private const int WM_SETFONT = 0x30; + private const int WM_FONTCHANGE = 0x1d; + + [SecuritySafeCritical] + protected override void OnFontChanged(EventArgs e) + { + base.OnFontChanged(e); + IntPtr hFont = this.EffectiveFont.ToHfont(); + SendMessage(this.Handle, WM_SETFONT, hFont, (IntPtr)(-1)); + SendMessage(this.Handle, WM_FONTCHANGE, IntPtr.Zero, IntPtr.Zero); + this.UpdateStyles(); + } + #endregion } -} \ No newline at end of file +}