diff --git a/.gitignore b/.gitignore index 57a1574..00581c6 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ *.user *.userosscache *.sln.docstates +.idea # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs diff --git a/DarkUI/Controls/DarkComboBox.cs b/DarkUI/Controls/DarkComboBox.cs new file mode 100644 index 0000000..88b9b51 --- /dev/null +++ b/DarkUI/Controls/DarkComboBox.cs @@ -0,0 +1,207 @@ +using DarkUI.Config; +using DarkUI.Icons; +using System; +using System.ComponentModel; +using System.Drawing; +using System.Windows.Forms; + +namespace DarkUI.Controls +{ + public class DarkComboBox : ComboBox + { + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public new Color ForeColor { get; set; } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public new Color BackColor { get; set; } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public new FlatStyle FlatStyle { get; set; } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public new ComboBoxStyle DropDownStyle { get; set; } + + private Bitmap _buffer; + + public DarkComboBox() : base() + { + SetStyle(ControlStyles.OptimizedDoubleBuffer | + ControlStyles.ResizeRedraw | + ControlStyles.UserPaint, true); + + DrawMode = DrawMode.OwnerDrawVariable; + + base.FlatStyle = FlatStyle.Flat; + base.DropDownStyle = ComboBoxStyle.DropDownList; + } + + protected override void Dispose(bool disposing) + { + if (disposing) + _buffer = null; + + base.Dispose(disposing); + } + + protected override void OnTabStopChanged(EventArgs e) + { + base.OnTabStopChanged(e); + Invalidate(); + } + + protected override void OnTabIndexChanged(EventArgs e) + { + base.OnTabIndexChanged(e); + Invalidate(); + } + + protected override void OnGotFocus(EventArgs e) + { + base.OnGotFocus(e); + Invalidate(); + } + + protected override void OnLostFocus(EventArgs e) + { + base.OnLostFocus(e); + Invalidate(); + } + + protected override void OnTextChanged(EventArgs e) + { + base.OnTextChanged(e); + Invalidate(); + } + + protected override void OnTextUpdate(EventArgs e) + { + base.OnTextUpdate(e); + Invalidate(); + } + + protected override void OnSelectedValueChanged(EventArgs e) + { + base.OnSelectedValueChanged(e); + Invalidate(); + } + + protected override void OnInvalidated(InvalidateEventArgs e) + { + base.OnInvalidated(e); + PaintCombobox(); + } + + private void PaintCombobox() + { + if (_buffer == null) + _buffer = new Bitmap(ClientRectangle.Width, ClientRectangle.Height); + + using (var g = Graphics.FromImage(_buffer)) + { + var rect = new Rectangle(0, 0, ClientSize.Width, ClientSize.Height); + + var textColor = Colors.LightText; + var borderColor = Colors.GreySelection; + var fillColor = Colors.LightBackground; + + if (Focused && TabStop) + borderColor = Colors.BlueHighlight; + + using (var b = new SolidBrush(fillColor)) + { + g.FillRectangle(b, rect); + } + + using (var p = new Pen(borderColor, 1)) + { + var modRect = new Rectangle(rect.Left, rect.Top, rect.Width - 1, rect.Height - 1); + g.DrawRectangle(p, modRect); + } + + var icon = ScrollIcons.scrollbar_arrow_hot; + g.DrawImageUnscaled(icon, + rect.Right - icon.Width - (Consts.Padding / 2), + (rect.Height / 2) - (icon.Height / 2)); + + var text = SelectedItem != null ? SelectedItem.ToString() : Text; + + using (var b = new SolidBrush(textColor)) + { + var padding = 2; + + var modRect = new Rectangle(rect.Left + padding, + rect.Top + padding, + rect.Width - icon.Width - (Consts.Padding / 2) - (padding * 2), + rect.Height - (padding * 2)); + + var stringFormat = new StringFormat + { + LineAlignment = StringAlignment.Center, + Alignment = StringAlignment.Near, + FormatFlags = StringFormatFlags.NoWrap, + Trimming = StringTrimming.EllipsisCharacter + }; + + g.DrawString(text, Font, b, modRect, stringFormat); + } + } + } + + protected override void OnPaint(PaintEventArgs e) + { + if (_buffer == null) + PaintCombobox(); + + var g = e.Graphics; + g.DrawImageUnscaled(_buffer, Point.Empty); + } + + protected override void OnDrawItem(DrawItemEventArgs e) + { + var g = e.Graphics; + var rect = e.Bounds; + + var textColor = Colors.LightText; + var fillColor = Colors.LightBackground; + + if ((e.State & DrawItemState.Selected) == DrawItemState.Selected || + (e.State & DrawItemState.Focus) == DrawItemState.Focus || + (e.State & DrawItemState.NoFocusRect) != DrawItemState.NoFocusRect) + fillColor = Colors.BlueSelection; + + using (var b = new SolidBrush(fillColor)) + { + g.FillRectangle(b, rect); + } + + if (e.Index >= 0 && e.Index < Items.Count) + { + var text = Items[e.Index].ToString(); + + using (var b = new SolidBrush(textColor)) + { + var padding = 2; + + var modRect = new Rectangle(rect.Left + padding, + rect.Top + padding, + rect.Width - (padding * 2), + rect.Height - (padding * 2)); + + var stringFormat = new StringFormat + { + LineAlignment = StringAlignment.Center, + Alignment = StringAlignment.Near, + FormatFlags = StringFormatFlags.NoWrap, + Trimming = StringTrimming.EllipsisCharacter + }; + + g.DrawString(text, Font, b, modRect, stringFormat); + } + } + } + } +} diff --git a/DarkUI/Controls/DarkGroupBox.cs b/DarkUI/Controls/DarkGroupBox.cs new file mode 100644 index 0000000..c3984e7 --- /dev/null +++ b/DarkUI/Controls/DarkGroupBox.cs @@ -0,0 +1,80 @@ +using DarkUI.Config; +using System; +using System.ComponentModel; +using System.Drawing; +using System.Windows.Forms; + +namespace DarkUI.Controls +{ + public class DarkGroupBox : GroupBox + { + private Color _borderColor = Colors.DarkBorder; + + [Category("Appearance")] + [Description("Determines the color of the border.")] + public Color BorderColor + { + get { return _borderColor; } + set + { + _borderColor = value; + Invalidate(); + } + } + + public DarkGroupBox() + { + SetStyle(ControlStyles.OptimizedDoubleBuffer | + ControlStyles.ResizeRedraw | + ControlStyles.UserPaint, true); + + ResizeRedraw = true; + DoubleBuffered = true; + } + + protected override void OnPaint(PaintEventArgs e) + { + var g = e.Graphics; + var rect = new Rectangle(0, 0, ClientSize.Width, ClientSize.Height); + var stringSize = g.MeasureString(Text, Font); + + var textColor = Colors.LightText; + var fillColor = Colors.GreyBackground; + + using (var b = new SolidBrush(fillColor)) + { + g.FillRectangle(b, rect); + } + + using (var p = new Pen(BorderColor, 1)) + { + var borderRect = new Rectangle(0, (int)stringSize.Height / 2, rect.Width - 1, rect.Height - ((int)stringSize.Height / 2) - 1); + g.DrawRectangle(p, borderRect); + } + + var textRect = new Rectangle(rect.Left + Consts.Padding, + rect.Top, + rect.Width - (Consts.Padding * 2), + (int)stringSize.Height); + + using (var b2 = new SolidBrush(fillColor)) + { + var modRect = new Rectangle(textRect.Left, textRect.Top, Math.Min(textRect.Width, (int)stringSize.Width), textRect.Height); + g.FillRectangle(b2, modRect); + } + + using (var b = new SolidBrush(textColor)) + { + var stringFormat = new StringFormat + { + LineAlignment = StringAlignment.Center, + Alignment = StringAlignment.Near, + FormatFlags = StringFormatFlags.NoWrap, + Trimming = StringTrimming.EllipsisCharacter + }; + + g.DrawString(Text, Font, b, textRect, stringFormat); + } + } + } +} diff --git a/DarkUI/Controls/DarkNumericUpDown.cs b/DarkUI/Controls/DarkNumericUpDown.cs new file mode 100644 index 0000000..d1d7873 --- /dev/null +++ b/DarkUI/Controls/DarkNumericUpDown.cs @@ -0,0 +1,153 @@ +using DarkUI.Config; +using System; +using System.ComponentModel; +using System.Drawing; +using System.Reflection; +using System.Security; +using System.Windows.Forms; + +namespace DarkUI.Controls +{ + public class DarkNumericUpDown : NumericUpDown + { + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public new Color ForeColor { get; set; } + + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public new Color BackColor { get; set; } + + private bool _mouseDown; + + public DarkNumericUpDown() + { + SetStyle(ControlStyles.OptimizedDoubleBuffer | + ControlStyles.ResizeRedraw | + ControlStyles.UserPaint, true); + + base.ForeColor = Color.Gainsboro; + base.BackColor = Colors.LightBackground; + + Controls[0].Paint += DarkNumericUpDown_Paint; + + try + { + // Prevent flickering, only if our assembly has reflection permission + Type type = Controls[0].GetType(); + BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Instance; + MethodInfo method = type.GetMethod("SetStyle", flags); + + if (method != null) + { + object[] param = { ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer, true }; + method.Invoke(Controls[0], param); + } + } + catch (SecurityException) + { + // Don't do anything, we are running in a trusted contex + } + } + + protected override void OnMouseMove(MouseEventArgs e) + { + Invalidate(); + } + + protected override void OnMouseDown(MouseEventArgs e) + { + _mouseDown = true; + Invalidate(); + } + + protected override void OnMouseUp(MouseEventArgs mevent) + { + _mouseDown = false; + Invalidate(); + } + + protected override void OnMouseEnter(EventArgs e) + { + base.OnMouseEnter(e); + Invalidate(); + } + + protected override void OnMouseLeave(EventArgs e) + { + base.OnMouseLeave(e); + Invalidate(); + } + + protected override void OnGotFocus(EventArgs e) + { + base.OnGotFocus(e); + Invalidate(); + } + + protected override void OnLostFocus(EventArgs e) + { + base.OnLostFocus(e); + Invalidate(); + } + + protected override void OnTextBoxLostFocus(object source, EventArgs e) + { + base.OnTextBoxLostFocus(source, e); + Invalidate(); + } + + private void DarkNumericUpDown_Paint(object sender, PaintEventArgs e) + { + var g = e.Graphics; + var rect = e.ClipRectangle; + + var fillColor = Colors.HeaderBackground; + + using (var b = new SolidBrush(fillColor)) + { + g.FillRectangle(b, rect); + } + + var mousePos = Controls[0].PointToClient(Cursor.Position); + + var upArea = new Rectangle(0, 0, rect.Width, rect.Height / 2); + var upHot = upArea.Contains(mousePos); + + var upIcon = upHot ? ScrollIcons.scrollbar_arrow_small_hot : ScrollIcons.scrollbar_arrow_small_standard; + if (upHot && _mouseDown) + upIcon = ScrollIcons.scrollbar_arrow_small_clicked; + + upIcon.RotateFlip(RotateFlipType.RotateNoneFlipY); + g.DrawImageUnscaled(upIcon, (upArea.Width / 2) - (upIcon.Width / 2), (upArea.Height / 2) - (upIcon.Height / 2)); + + var downArea = new Rectangle(0, rect.Height / 2, rect.Width, rect.Height / 2); + var downHot = downArea.Contains(mousePos); + + var downIcon = downHot ? ScrollIcons.scrollbar_arrow_small_hot : ScrollIcons.scrollbar_arrow_small_standard; + if (downHot && _mouseDown) + downIcon = ScrollIcons.scrollbar_arrow_small_clicked; + + g.DrawImageUnscaled(downIcon, (downArea.Width / 2) - (downIcon.Width / 2), downArea.Top + (downArea.Height / 2) - (downIcon.Height / 2)); + } + + protected override void OnPaint(PaintEventArgs e) + { + base.OnPaint(e); + + var g = e.Graphics; + var rect = new Rectangle(0, 0, ClientSize.Width, ClientSize.Height); + + var borderColor = Colors.GreySelection; + + if (Focused && TabStop) + borderColor = Colors.BlueHighlight; + + using (var p = new Pen(borderColor, 1)) + { + var modRect = new Rectangle(rect.Left, rect.Top, rect.Width - 1, rect.Height - 1); + g.DrawRectangle(p, modRect); + } + } + } +} diff --git a/DarkUI/DarkUI.csproj b/DarkUI/DarkUI.csproj index f4fcfc8..9b7b7e2 100644 --- a/DarkUI/DarkUI.csproj +++ b/DarkUI/DarkUI.csproj @@ -54,8 +54,17 @@ Component + + Component + + + Component + + + Component + Component @@ -312,6 +321,15 @@ + + + + + + + + +