mirror of
https://github.com/colhountech/DarkUI.Net5.git
synced 2025-07-02 07:09:27 +03:00
Added icons to list views
This commit is contained in:
parent
51047714f5
commit
6093a15ca4
@ -38,6 +38,8 @@ namespace DarkUI.Controls
|
||||
|
||||
public FontStyle FontStyle { get; set; }
|
||||
|
||||
public Bitmap Icon { get; set; }
|
||||
|
||||
public object Tag { get; set; }
|
||||
|
||||
#endregion
|
||||
|
@ -23,6 +23,8 @@ namespace DarkUI.Controls
|
||||
private int _itemHeight = 20;
|
||||
private bool _multiSelect;
|
||||
|
||||
private readonly int _iconSize = 16;
|
||||
|
||||
private ObservableCollection<DarkListItem> _items;
|
||||
private List<int> _selectedIndices;
|
||||
private int _anchoredItemStart = -1;
|
||||
@ -79,6 +81,11 @@ namespace DarkUI.Controls
|
||||
set { _multiSelect = value; }
|
||||
}
|
||||
|
||||
[Category("Appearance")]
|
||||
[Description("Determines whether icons are rendered with the list items.")]
|
||||
[DefaultValue(false)]
|
||||
public bool ShowIcons { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor Region
|
||||
@ -397,6 +404,9 @@ namespace DarkUI.Controls
|
||||
var size = g.MeasureString(item.Text, Font);
|
||||
size.Width++;
|
||||
|
||||
if (ShowIcons)
|
||||
size.Width += _iconSize + 8;
|
||||
|
||||
item.Area = new Rectangle(item.Area.Left, item.Area.Top, (int)size.Width, item.Area.Height);
|
||||
}
|
||||
|
||||
@ -523,6 +533,12 @@ namespace DarkUI.Controls
|
||||
g.DrawLine(p, new Point(rect.Left, rect.Bottom - 1), new Point(rect.Right, rect.Bottom - 1));
|
||||
}*/
|
||||
|
||||
// Icon
|
||||
if (ShowIcons && Items[i].Icon != null)
|
||||
{
|
||||
g.DrawImageUnscaled(Items[i].Icon, new Point(rect.Left + 5, rect.Top + (rect.Height / 2) - (_iconSize / 2)));
|
||||
}
|
||||
|
||||
// Text
|
||||
using (var b = new SolidBrush(Items[i].TextColor))
|
||||
{
|
||||
@ -535,6 +551,10 @@ namespace DarkUI.Controls
|
||||
var modFont = new Font(Font, Items[i].FontStyle);
|
||||
|
||||
var modRect = new Rectangle(rect.Left + 2, rect.Top, rect.Width, rect.Height);
|
||||
|
||||
if (ShowIcons)
|
||||
modRect.X += _iconSize + 8;
|
||||
|
||||
g.DrawString(Items[i].Text, modFont, b, modRect, stringFormat);
|
||||
}
|
||||
}
|
||||
|
1
Example/Forms/Docking/DockLayers.Designer.cs
generated
1
Example/Forms/Docking/DockLayers.Designer.cs
generated
@ -39,6 +39,7 @@ namespace Example
|
||||
this.lstLayers.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.lstLayers.Location = new System.Drawing.Point(0, 25);
|
||||
this.lstLayers.Name = "lstLayers";
|
||||
this.lstLayers.ShowIcons = true;
|
||||
this.lstLayers.Size = new System.Drawing.Size(280, 425);
|
||||
this.lstLayers.TabIndex = 0;
|
||||
this.lstLayers.Text = "darkListView1";
|
||||
|
@ -15,6 +15,7 @@ namespace Example
|
||||
for (var i = 0; i < 100; i++)
|
||||
{
|
||||
var item = new DarkListItem($"List item #{i}");
|
||||
item.Icon = Icons.application_16x;
|
||||
lstLayers.Items.Add(item);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user