From 7e80b71546fbe3d42b59cf1bb6ea2c5515664d28 Mon Sep 17 00:00:00 2001 From: Robin Perris Date: Fri, 10 Jan 2020 09:43:28 +0000 Subject: [PATCH] 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