From 11891a3144687a70e958f099355e1acb515d2f74 Mon Sep 17 00:00:00 2001 From: Robin Perris Date: Thu, 9 Jan 2020 15:12:41 +0000 Subject: [PATCH 1/7] Added .idea to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) 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 From d6c7da9a922044440ee250c2c60883b55205382f Mon Sep 17 00:00:00 2001 From: Robin Perris Date: Thu, 9 Jan 2020 18:58:33 +0000 Subject: [PATCH 2/7] Created DarkComboBox --- DarkUI/Controls/DarkComboBox.cs | 162 ++++++++++++++++++ DarkUI/DarkUI.csproj | 3 + .../Forms/Dialogs/DialogControls.Designer.cs | 48 ++++++ Example/Forms/Dialogs/DialogControls.resx | 7 + 4 files changed, 220 insertions(+) create mode 100644 DarkUI/Controls/DarkComboBox.cs diff --git a/DarkUI/Controls/DarkComboBox.cs b/DarkUI/Controls/DarkComboBox.cs new file mode 100644 index 0000000..8e480de --- /dev/null +++ b/DarkUI/Controls/DarkComboBox.cs @@ -0,0 +1,162 @@ +using DarkUI.Config; +using DarkUI.Icons; +using System; +using System.ComponentModel; +using System.Drawing; +using System.Windows.Forms; +using DarkUI.Extensions; + +namespace DarkUI.Controls +{ + public class DarkComboBox : ComboBox + { + public DarkComboBox() : base() + { + SetStyle(ControlStyles.OptimizedDoubleBuffer | + ControlStyles.ResizeRedraw | + ControlStyles.UserPaint, true); + + DrawMode = DrawMode.OwnerDrawVariable; + + base.FlatStyle = FlatStyle.Flat; + base.DropDownStyle = ComboBoxStyle.DropDownList; + } + + [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; } + + public new void Invalidate() + { + base.Invalidate(); + } + + protected override void OnTextChanged(EventArgs e) + { + Invalidate(); + + base.OnTextChanged(e); + } + + protected override void OnTextUpdate(EventArgs e) + { + Invalidate(); + + base.OnTextUpdate(e); + } + + protected override void OnSelectedValueChanged(EventArgs e) + { + Invalidate(); + + base.OnSelectedValueChanged(e); + } + + 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 textOffsetX = 2; + var textOffsetY = 2; + + var modRect = new Rectangle(rect.Left + textOffsetX, + rect.Top + textOffsetY, + rect.Width - textOffsetX, + rect.Height - textOffsetY); + + var stringFormat = new StringFormat + { + LineAlignment = StringAlignment.Center, + Alignment = StringAlignment.Near, + Trimming = StringTrimming.EllipsisCharacter + }; + + g.DrawString(text, Font, b, modRect, stringFormat); + } + } + } + + protected override void OnPaint(PaintEventArgs e) + { + var g = e.Graphics; + 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 textOffsetX = 2; + var textOffsetY = 2; + + var modRect = new Rectangle(rect.Left + textOffsetX, + rect.Top + textOffsetY, + rect.Width - textOffsetX, + rect.Height - textOffsetY); + + var stringFormat = new StringFormat + { + LineAlignment = StringAlignment.Center, + Alignment = StringAlignment.Near, + Trimming = StringTrimming.EllipsisCharacter + }; + + g.DrawString(text, Font, b, modRect, stringFormat); + } + } + } +} diff --git a/DarkUI/DarkUI.csproj b/DarkUI/DarkUI.csproj index 6f4914b..ef05429 100644 --- a/DarkUI/DarkUI.csproj +++ b/DarkUI/DarkUI.csproj @@ -50,6 +50,9 @@ Component + + Component + diff --git a/Example/Forms/Dialogs/DialogControls.Designer.cs b/Example/Forms/Dialogs/DialogControls.Designer.cs index 90598b8..6b319df 100644 --- a/Example/Forms/Dialogs/DialogControls.Designer.cs +++ b/Example/Forms/Dialogs/DialogControls.Designer.cs @@ -39,6 +39,9 @@ namespace Example this.lstTest = new DarkUI.Controls.DarkListView(); this.pnlMessageBox = new DarkUI.Controls.DarkSectionPanel(); this.panel1 = new System.Windows.Forms.Panel(); + this.panel6 = new System.Windows.Forms.Panel(); + this.darkComboBox1 = new DarkUI.Controls.DarkComboBox(); + this.darkTitle4 = new DarkUI.Controls.DarkTitle(); this.panel5 = new System.Windows.Forms.Panel(); this.darkRadioButton3 = new DarkUI.Controls.DarkRadioButton(); this.darkRadioButton2 = new DarkUI.Controls.DarkRadioButton(); @@ -59,6 +62,7 @@ namespace Example this.pnlListView.SuspendLayout(); this.pnlMessageBox.SuspendLayout(); this.panel1.SuspendLayout(); + this.panel6.SuspendLayout(); this.panel5.SuspendLayout(); this.panel4.SuspendLayout(); this.panel3.SuspendLayout(); @@ -150,6 +154,7 @@ namespace Example // // panel1 // + this.panel1.Controls.Add(this.panel6); this.panel1.Controls.Add(this.panel5); this.panel1.Controls.Add(this.panel4); this.panel1.Controls.Add(this.panel3); @@ -161,6 +166,45 @@ namespace Example this.panel1.Size = new System.Drawing.Size(220, 374); this.panel1.TabIndex = 0; // + // panel6 + // + this.panel6.Controls.Add(this.darkComboBox1); + this.panel6.Controls.Add(this.darkTitle4); + this.panel6.Dock = System.Windows.Forms.DockStyle.Top; + this.panel6.Location = new System.Drawing.Point(10, 285); + this.panel6.Name = "panel6"; + this.panel6.Size = new System.Drawing.Size(200, 100); + this.panel6.TabIndex = 13; + // + // darkComboBox1 + // + this.darkComboBox1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(49)))), ((int)(((byte)(51)))), ((int)(((byte)(53))))); + this.darkComboBox1.Dock = System.Windows.Forms.DockStyle.Top; + this.darkComboBox1.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable; + this.darkComboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.darkComboBox1.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.darkComboBox1.ForeColor = System.Drawing.Color.Gainsboro; + this.darkComboBox1.FormattingEnabled = true; + this.darkComboBox1.Items.AddRange(new object[] { + "Item 1", + "Item 2", + "Item 3", + "Item 4"}); + this.darkComboBox1.Location = new System.Drawing.Point(0, 26); + this.darkComboBox1.Name = "darkComboBox1"; + this.darkComboBox1.Size = new System.Drawing.Size(200, 24); + this.darkComboBox1.TabIndex = 17; + this.darkComboBox1.Text = "Item 1"; + // + // darkTitle4 + // + this.darkTitle4.Dock = System.Windows.Forms.DockStyle.Top; + this.darkTitle4.Location = new System.Drawing.Point(0, 0); + this.darkTitle4.Name = "darkTitle4"; + this.darkTitle4.Size = new System.Drawing.Size(200, 26); + this.darkTitle4.TabIndex = 16; + this.darkTitle4.Text = "Additional controls"; + // // panel5 // this.panel5.Controls.Add(this.darkRadioButton3); @@ -331,6 +375,7 @@ namespace Example this.pnlMessageBox.ResumeLayout(false); this.panel1.ResumeLayout(false); this.panel1.PerformLayout(); + this.panel6.ResumeLayout(false); this.panel5.ResumeLayout(false); this.panel5.PerformLayout(); this.panel4.ResumeLayout(false); @@ -365,5 +410,8 @@ namespace Example private DarkTitle darkTitle1; private DarkTitle darkTitle2; private DarkTitle darkTitle3; + private System.Windows.Forms.Panel panel6; + private DarkTitle darkTitle4; + private DarkComboBox darkComboBox1; } } \ No newline at end of file diff --git a/Example/Forms/Dialogs/DialogControls.resx b/Example/Forms/Dialogs/DialogControls.resx index 16202c3..8a7b1de 100644 --- a/Example/Forms/Dialogs/DialogControls.resx +++ b/Example/Forms/Dialogs/DialogControls.resx @@ -118,6 +118,13 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + iVBORw0KGgoAAAANSUhEUgAAAAkAAAAFCAYAAACXU8ZrAAAAIGNIUk0AAHolAACAgwAA+f8AAIDpAAB1 + MAAA6mAAADqYAAAXb5JfxUYAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAvSURBVBhXY4iJiflPCDP8//8f + r0KQPFgRLoUwObgiEMamAIRRFIEwuoL///8zAAC5cW+geGnZqAAAAABJRU5ErkJggg== + + AAABAAEAECAAAAEAIAA8AQAAFgAAAIlQTkcNChoKAAAADUlIRFIAAAAQAAAAEAgGAAAAH/P/YQAAAAFz From 7e80b71546fbe3d42b59cf1bb6ea2c5515664d28 Mon Sep 17 00:00:00 2001 From: Robin Perris Date: Fri, 10 Jan 2020 09:43:28 +0000 Subject: [PATCH 3/7] Proper sizing & clipping on text in a DarkComboBox --- DarkUI/Controls/DarkComboBox.cs | 24 +++++++++---------- .../Forms/Dialogs/DialogControls.Designer.cs | 7 +----- Example/Forms/Dialogs/DialogControls.resx | 7 ------ 3 files changed, 13 insertions(+), 25 deletions(-) diff --git a/DarkUI/Controls/DarkComboBox.cs b/DarkUI/Controls/DarkComboBox.cs index 8e480de..6a3ee51 100644 --- a/DarkUI/Controls/DarkComboBox.cs +++ b/DarkUI/Controls/DarkComboBox.cs @@ -88,18 +88,18 @@ namespace DarkUI.Controls using (var b = new SolidBrush(textColor)) { - var textOffsetX = 2; - var textOffsetY = 2; + var padding = 2; - var modRect = new Rectangle(rect.Left + textOffsetX, - rect.Top + textOffsetY, - rect.Width - textOffsetX, - rect.Height - textOffsetY); + 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 }; @@ -140,18 +140,18 @@ namespace DarkUI.Controls using (var b = new SolidBrush(textColor)) { - var textOffsetX = 2; - var textOffsetY = 2; + var padding = 2; - var modRect = new Rectangle(rect.Left + textOffsetX, - rect.Top + textOffsetY, - rect.Width - textOffsetX, - rect.Height - textOffsetY); + 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 }; diff --git a/Example/Forms/Dialogs/DialogControls.Designer.cs b/Example/Forms/Dialogs/DialogControls.Designer.cs index 6b319df..7a44f4a 100644 --- a/Example/Forms/Dialogs/DialogControls.Designer.cs +++ b/Example/Forms/Dialogs/DialogControls.Designer.cs @@ -178,23 +178,18 @@ namespace Example // // darkComboBox1 // - this.darkComboBox1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(49)))), ((int)(((byte)(51)))), ((int)(((byte)(53))))); this.darkComboBox1.Dock = System.Windows.Forms.DockStyle.Top; this.darkComboBox1.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable; - this.darkComboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.darkComboBox1.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.darkComboBox1.ForeColor = System.Drawing.Color.Gainsboro; this.darkComboBox1.FormattingEnabled = true; this.darkComboBox1.Items.AddRange(new object[] { "Item 1", "Item 2", - "Item 3", + "This is a really long item in the collection to check out how text is clipped", "Item 4"}); this.darkComboBox1.Location = new System.Drawing.Point(0, 26); this.darkComboBox1.Name = "darkComboBox1"; this.darkComboBox1.Size = new System.Drawing.Size(200, 24); this.darkComboBox1.TabIndex = 17; - this.darkComboBox1.Text = "Item 1"; // // darkTitle4 // diff --git a/Example/Forms/Dialogs/DialogControls.resx b/Example/Forms/Dialogs/DialogControls.resx index 8a7b1de..16202c3 100644 --- a/Example/Forms/Dialogs/DialogControls.resx +++ b/Example/Forms/Dialogs/DialogControls.resx @@ -118,13 +118,6 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - iVBORw0KGgoAAAANSUhEUgAAAAkAAAAFCAYAAACXU8ZrAAAAIGNIUk0AAHolAACAgwAA+f8AAIDpAAB1 - MAAA6mAAADqYAAAXb5JfxUYAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAvSURBVBhXY4iJiflPCDP8//8f - r0KQPFgRLoUwObgiEMamAIRRFIEwuoL///8zAAC5cW+geGnZqAAAAABJRU5ErkJggg== - - AAABAAEAECAAAAEAIAA8AQAAFgAAAIlQTkcNChoKAAAADUlIRFIAAAAQAAAAEAgGAAAAH/P/YQAAAAFz From 766c4292a9a80ba790c589e8e4d6c322718ac64d Mon Sep 17 00:00:00 2001 From: Robin Perris Date: Fri, 10 Jan 2020 09:57:32 +0000 Subject: [PATCH 4/7] Draw to a buffer to avoid tearing --- DarkUI/Controls/DarkComboBox.cs | 195 ++++++++++++++++++++------------ 1 file changed, 120 insertions(+), 75 deletions(-) diff --git a/DarkUI/Controls/DarkComboBox.cs b/DarkUI/Controls/DarkComboBox.cs index 6a3ee51..88b9b51 100644 --- a/DarkUI/Controls/DarkComboBox.cs +++ b/DarkUI/Controls/DarkComboBox.cs @@ -4,24 +4,11 @@ using System; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; -using DarkUI.Extensions; namespace DarkUI.Controls { public class DarkComboBox : ComboBox { - public DarkComboBox() : base() - { - SetStyle(ControlStyles.OptimizedDoubleBuffer | - ControlStyles.ResizeRedraw | - ControlStyles.UserPaint, true); - - DrawMode = DrawMode.OwnerDrawVariable; - - base.FlatStyle = FlatStyle.Flat; - base.DropDownStyle = ComboBoxStyle.DropDownList; - } - [Browsable(false)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public new Color ForeColor { get; set; } @@ -38,30 +25,139 @@ namespace DarkUI.Controls [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public new ComboBoxStyle DropDownStyle { get; set; } - public new void Invalidate() + private Bitmap _buffer; + + public DarkComboBox() : base() { - base.Invalidate(); + 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) { - Invalidate(); - base.OnTextChanged(e); + Invalidate(); } protected override void OnTextUpdate(EventArgs e) { - Invalidate(); - base.OnTextUpdate(e); + Invalidate(); } protected override void OnSelectedValueChanged(EventArgs e) { - Invalidate(); - 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) @@ -72,8 +168,8 @@ namespace DarkUI.Controls var textColor = Colors.LightText; var fillColor = Colors.LightBackground; - if ((e.State & DrawItemState.Selected) == DrawItemState.Selected || - (e.State & DrawItemState.Focus) == DrawItemState.Focus || + if ((e.State & DrawItemState.Selected) == DrawItemState.Selected || + (e.State & DrawItemState.Focus) == DrawItemState.Focus || (e.State & DrawItemState.NoFocusRect) != DrawItemState.NoFocusRect) fillColor = Colors.BlueSelection; @@ -85,7 +181,7 @@ namespace DarkUI.Controls if (e.Index >= 0 && e.Index < Items.Count) { var text = Items[e.Index].ToString(); - + using (var b = new SolidBrush(textColor)) { var padding = 2; @@ -107,56 +203,5 @@ namespace DarkUI.Controls } } } - - protected override void OnPaint(PaintEventArgs e) - { - var g = e.Graphics; - 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); - } - } } } From d7f3cd40fb07c14ca46e89f7d992f57f4bb5fddc Mon Sep 17 00:00:00 2001 From: Robin Perris Date: Fri, 10 Jan 2020 10:38:16 +0000 Subject: [PATCH 5/7] Added DarkGroupBox --- DarkUI/Controls/DarkGroupBox.cs | 80 +++++++++++++++++++ DarkUI/DarkUI.csproj | 3 + .../Forms/Dialogs/DialogControls.Designer.cs | 66 +++++++-------- 3 files changed, 113 insertions(+), 36 deletions(-) create mode 100644 DarkUI/Controls/DarkGroupBox.cs 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/DarkUI.csproj b/DarkUI/DarkUI.csproj index ef05429..2b859c3 100644 --- a/DarkUI/DarkUI.csproj +++ b/DarkUI/DarkUI.csproj @@ -55,6 +55,9 @@ + + Component + Component diff --git a/Example/Forms/Dialogs/DialogControls.Designer.cs b/Example/Forms/Dialogs/DialogControls.Designer.cs index 7a44f4a..a34247a 100644 --- a/Example/Forms/Dialogs/DialogControls.Designer.cs +++ b/Example/Forms/Dialogs/DialogControls.Designer.cs @@ -39,9 +39,8 @@ namespace Example this.lstTest = new DarkUI.Controls.DarkListView(); this.pnlMessageBox = new DarkUI.Controls.DarkSectionPanel(); this.panel1 = new System.Windows.Forms.Panel(); - this.panel6 = new System.Windows.Forms.Panel(); + this.darkGroupBox1 = new DarkUI.Controls.DarkGroupBox(); this.darkComboBox1 = new DarkUI.Controls.DarkComboBox(); - this.darkTitle4 = new DarkUI.Controls.DarkTitle(); this.panel5 = new System.Windows.Forms.Panel(); this.darkRadioButton3 = new DarkUI.Controls.DarkRadioButton(); this.darkRadioButton2 = new DarkUI.Controls.DarkRadioButton(); @@ -62,7 +61,7 @@ namespace Example this.pnlListView.SuspendLayout(); this.pnlMessageBox.SuspendLayout(); this.panel1.SuspendLayout(); - this.panel6.SuspendLayout(); + this.darkGroupBox1.SuspendLayout(); this.panel5.SuspendLayout(); this.panel4.SuspendLayout(); this.panel3.SuspendLayout(); @@ -76,7 +75,7 @@ namespace Example this.pnlMain.Location = new System.Drawing.Point(0, 0); this.pnlMain.Name = "pnlMain"; this.pnlMain.Padding = new System.Windows.Forms.Padding(5, 10, 5, 0); - this.pnlMain.Size = new System.Drawing.Size(708, 410); + this.pnlMain.Size = new System.Drawing.Size(708, 619); this.pnlMain.TabIndex = 2; // // tblMain @@ -93,7 +92,7 @@ namespace Example this.tblMain.Name = "tblMain"; this.tblMain.RowCount = 1; this.tblMain.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); - this.tblMain.Size = new System.Drawing.Size(698, 400); + this.tblMain.Size = new System.Drawing.Size(698, 609); this.tblMain.TabIndex = 0; // // pnlTreeView @@ -104,7 +103,7 @@ namespace Example this.pnlTreeView.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); this.pnlTreeView.Name = "pnlTreeView"; this.pnlTreeView.SectionHeader = "Tree view test"; - this.pnlTreeView.Size = new System.Drawing.Size(224, 400); + this.pnlTreeView.Size = new System.Drawing.Size(224, 609); this.pnlTreeView.TabIndex = 14; // // treeTest @@ -116,7 +115,7 @@ namespace Example this.treeTest.MultiSelect = true; this.treeTest.Name = "treeTest"; this.treeTest.ShowIcons = true; - this.treeTest.Size = new System.Drawing.Size(222, 374); + this.treeTest.Size = new System.Drawing.Size(222, 583); this.treeTest.TabIndex = 0; this.treeTest.Text = "darkTreeView1"; // @@ -128,7 +127,7 @@ namespace Example this.pnlListView.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); this.pnlListView.Name = "pnlListView"; this.pnlListView.SectionHeader = "List view test"; - this.pnlListView.Size = new System.Drawing.Size(222, 400); + this.pnlListView.Size = new System.Drawing.Size(222, 609); this.pnlListView.TabIndex = 13; // // lstTest @@ -137,7 +136,7 @@ namespace Example this.lstTest.Location = new System.Drawing.Point(1, 25); this.lstTest.MultiSelect = true; this.lstTest.Name = "lstTest"; - this.lstTest.Size = new System.Drawing.Size(220, 374); + this.lstTest.Size = new System.Drawing.Size(220, 583); this.lstTest.TabIndex = 7; this.lstTest.Text = "darkListView1"; // @@ -149,12 +148,12 @@ namespace Example this.pnlMessageBox.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0); this.pnlMessageBox.Name = "pnlMessageBox"; this.pnlMessageBox.SectionHeader = "Controls test"; - this.pnlMessageBox.Size = new System.Drawing.Size(222, 400); + this.pnlMessageBox.Size = new System.Drawing.Size(222, 609); this.pnlMessageBox.TabIndex = 12; // // panel1 // - this.panel1.Controls.Add(this.panel6); + this.panel1.Controls.Add(this.darkGroupBox1); this.panel1.Controls.Add(this.panel5); this.panel1.Controls.Add(this.panel4); this.panel1.Controls.Add(this.panel3); @@ -163,18 +162,23 @@ namespace Example this.panel1.Location = new System.Drawing.Point(1, 25); this.panel1.Name = "panel1"; this.panel1.Padding = new System.Windows.Forms.Padding(10); - this.panel1.Size = new System.Drawing.Size(220, 374); + this.panel1.Size = new System.Drawing.Size(220, 583); this.panel1.TabIndex = 0; // - // panel6 + // darkGroupBox1 // - this.panel6.Controls.Add(this.darkComboBox1); - this.panel6.Controls.Add(this.darkTitle4); - this.panel6.Dock = System.Windows.Forms.DockStyle.Top; - this.panel6.Location = new System.Drawing.Point(10, 285); - this.panel6.Name = "panel6"; - this.panel6.Size = new System.Drawing.Size(200, 100); - this.panel6.TabIndex = 13; + this.darkGroupBox1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(60)))), ((int)(((byte)(63)))), ((int)(((byte)(65))))); + this.darkGroupBox1.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(51)))), ((int)(((byte)(51)))), ((int)(((byte)(51))))); + this.darkGroupBox1.Controls.Add(this.darkComboBox1); + this.darkGroupBox1.Dock = System.Windows.Forms.DockStyle.Top; + this.darkGroupBox1.ForeColor = System.Drawing.Color.Gainsboro; + this.darkGroupBox1.Location = new System.Drawing.Point(10, 285); + this.darkGroupBox1.Name = "darkGroupBox1"; + this.darkGroupBox1.Padding = new System.Windows.Forms.Padding(10); + this.darkGroupBox1.Size = new System.Drawing.Size(200, 144); + this.darkGroupBox1.TabIndex = 14; + this.darkGroupBox1.TabStop = false; + this.darkGroupBox1.Text = "DarkUI 2.0 Controls"; // // darkComboBox1 // @@ -186,19 +190,10 @@ namespace Example "Item 2", "This is a really long item in the collection to check out how text is clipped", "Item 4"}); - this.darkComboBox1.Location = new System.Drawing.Point(0, 26); + this.darkComboBox1.Location = new System.Drawing.Point(10, 26); this.darkComboBox1.Name = "darkComboBox1"; - this.darkComboBox1.Size = new System.Drawing.Size(200, 24); - this.darkComboBox1.TabIndex = 17; - // - // darkTitle4 - // - this.darkTitle4.Dock = System.Windows.Forms.DockStyle.Top; - this.darkTitle4.Location = new System.Drawing.Point(0, 0); - this.darkTitle4.Name = "darkTitle4"; - this.darkTitle4.Size = new System.Drawing.Size(200, 26); - this.darkTitle4.TabIndex = 16; - this.darkTitle4.Text = "Additional controls"; + this.darkComboBox1.Size = new System.Drawing.Size(180, 24); + this.darkComboBox1.TabIndex = 18; // // panel5 // @@ -355,7 +350,7 @@ namespace Example // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(708, 455); + this.ClientSize = new System.Drawing.Size(708, 664); this.Controls.Add(this.pnlMain); this.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); @@ -370,7 +365,7 @@ namespace Example this.pnlMessageBox.ResumeLayout(false); this.panel1.ResumeLayout(false); this.panel1.PerformLayout(); - this.panel6.ResumeLayout(false); + this.darkGroupBox1.ResumeLayout(false); this.panel5.ResumeLayout(false); this.panel5.PerformLayout(); this.panel4.ResumeLayout(false); @@ -405,8 +400,7 @@ namespace Example private DarkTitle darkTitle1; private DarkTitle darkTitle2; private DarkTitle darkTitle3; - private System.Windows.Forms.Panel panel6; - private DarkTitle darkTitle4; + private DarkGroupBox darkGroupBox1; private DarkComboBox darkComboBox1; } } \ No newline at end of file From 5712a441b435f42d8c91168612c1fb86f3aab487 Mon Sep 17 00:00:00 2001 From: Robin Perris Date: Fri, 10 Jan 2020 14:54:06 +0000 Subject: [PATCH 6/7] Added DarkNumericUpDown --- DarkUI/Controls/DarkNumericUpDown.cs | 153 ++++++++++++++++++ DarkUI/DarkUI.csproj | 12 ++ DarkUI/Icons/ScrollIcons.Designer.cs | 34 +++- DarkUI/Icons/ScrollIcons.resx | 9 ++ .../scrollbar_arrow_small_clicked.png | Bin 0 -> 2011 bytes .../Resources/scrollbar_arrow_small_hot.png | Bin 0 -> 2004 bytes .../scrollbar_arrow_small_standard.png | Bin 0 -> 2012 bytes .../Forms/Dialogs/DialogControls.Designer.cs | 101 +++++++++--- 8 files changed, 286 insertions(+), 23 deletions(-) create mode 100644 DarkUI/Controls/DarkNumericUpDown.cs create mode 100644 DarkUI/Resources/scrollbar_arrow_small_clicked.png create mode 100644 DarkUI/Resources/scrollbar_arrow_small_hot.png create mode 100644 DarkUI/Resources/scrollbar_arrow_small_standard.png 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 2b859c3..632b48c 100644 --- a/DarkUI/DarkUI.csproj +++ b/DarkUI/DarkUI.csproj @@ -58,6 +58,9 @@ Component + + Component + Component @@ -298,6 +301,15 @@ + + + + + + + + +