Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions MetroFramework.Design/MetroRadioButtonDesigner.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
68 changes: 47 additions & 21 deletions MetroFramework/Controls/MetroTabControl.cs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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)
{ }
}

Expand All @@ -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)]
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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)
Expand All @@ -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

Expand All @@ -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();
}
Expand Down Expand Up @@ -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);
}
Expand All @@ -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
}
}
}