Proper sizing & clipping on text in a DarkComboBox

This commit is contained in:
Robin Perris 2020-01-10 09:43:28 +00:00
parent d6c7da9a92
commit 7e80b71546
3 changed files with 13 additions and 25 deletions

View File

@ -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
};

View File

@ -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
//

View File

@ -118,13 +118,6 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="darkComboBox1.ButtonIcon" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAAAkAAAAFCAYAAACXU8ZrAAAAIGNIUk0AAHolAACAgwAA+f8AAIDpAAB1
MAAA6mAAADqYAAAXb5JfxUYAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAvSURBVBhXY4iJiflPCDP8//8f
r0KQPFgRLoUwObgiEMamAIRRFIEwuoL///8zAAC5cW+geGnZqAAAAABJRU5ErkJggg==
</value>
</data>
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
AAABAAEAECAAAAEAIAA8AQAAFgAAAIlQTkcNChoKAAAADUlIRFIAAAAQAAAAEAgGAAAAH/P/YQAAAAFz