diff --git a/Bin/net40/SunnyUI.Demo.exe b/Bin/net40/SunnyUI.Demo.exe index 275d931b..f0081ea9 100644 Binary files a/Bin/net40/SunnyUI.Demo.exe and b/Bin/net40/SunnyUI.Demo.exe differ diff --git a/Bin/net40/SunnyUI.dll b/Bin/net40/SunnyUI.dll index c04c4e1d..9241c18b 100644 Binary files a/Bin/net40/SunnyUI.dll and b/Bin/net40/SunnyUI.dll differ diff --git a/SunnyUI.Demo/Controls/FListBox.Designer.cs b/SunnyUI.Demo/Controls/FListBox.Designer.cs index 87ce3a17..6d17e979 100644 --- a/SunnyUI.Demo/Controls/FListBox.Designer.cs +++ b/SunnyUI.Demo/Controls/FListBox.Designer.cs @@ -77,6 +77,7 @@ namespace Sunny.UI.Demo this.uiListBox1.Size = new System.Drawing.Size(270, 343); this.uiListBox1.TabIndex = 27; this.uiListBox1.Text = "uiListBox1"; + this.uiListBox1.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.ListBox_DrawItem); this.uiListBox1.ItemDoubleClick += new System.EventHandler(this.uiListBox1_ItemDoubleClick); // // uiLine2 @@ -118,7 +119,7 @@ namespace Sunny.UI.Demo this.uiImageListBox1.TextAlignment = System.Drawing.ContentAlignment.MiddleCenter; this.uiImageListBox1.ItemDoubleClick += new System.EventHandler(this.uiImageListBox1_ItemDoubleClick); // - // FListBox1 + // FListBox // this.AllowShowTitle = true; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; @@ -129,7 +130,7 @@ namespace Sunny.UI.Demo this.Controls.Add(this.uiLine2); this.Controls.Add(this.uiLine1); this.Controls.Add(this.uiImageListBox1); - this.Name = "FListBox1"; + this.Name = "FListBox"; this.Padding = new System.Windows.Forms.Padding(0, 35, 0, 0); this.ShowTitle = true; this.Symbol = 61474; diff --git a/SunnyUI.Demo/Controls/FListBox.cs b/SunnyUI.Demo/Controls/FListBox.cs index 36c8b716..8abc09fb 100644 --- a/SunnyUI.Demo/Controls/FListBox.cs +++ b/SunnyUI.Demo/Controls/FListBox.cs @@ -1,5 +1,6 @@ using Sunny.UI.Demo.Properties; using System; +using System.Drawing; namespace Sunny.UI.Demo { @@ -10,6 +11,17 @@ namespace Sunny.UI.Demo InitializeComponent(); } + private void ListBox_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) + { + string text = uiListBox1.GetItemText(e.Index); + + if (text.Contains("6")) + { + e.Graphics.FillRectangle(UIColor.Green, e.Bounds); + e.Graphics.DrawString(text, e.Font, Color.Blue, e.Bounds); + } + } + public override void Init() { uiListBox1.Items.Clear(); diff --git a/SunnyUI/Controls/UIListBox.cs b/SunnyUI/Controls/UIListBox.cs index c0d0c400..fd2046fc 100644 --- a/SunnyUI/Controls/UIListBox.cs +++ b/SunnyUI/Controls/UIListBox.cs @@ -82,12 +82,20 @@ namespace Sunny.UI listbox.KeyUp += Listbox_KeyUp; listbox.MouseEnter += Listbox_MouseEnter; listbox.MouseLeave += Listbox_MouseLeave; + listbox.DrawItem += Listbox_DrawItem; timer = new Timer(); timer.Tick += Timer_Tick; timer.Start(); } + private void Listbox_DrawItem(object sender, DrawItemEventArgs e) + { + DrawItem?.Invoke(sender, e); + } + + public event DrawItemEventHandler DrawItem; + protected override void Dispose(bool disposing) { base.Dispose(disposing); @@ -574,6 +582,12 @@ namespace Sunny.UI { return listbox.GetItemText(item); } + + public string GetItemText(int index) + { + if (index < 0 || index >= Items.Count) return string.Empty; + return GetItemText(Items[index]); + } } /// @@ -829,8 +843,6 @@ namespace Sunny.UI protected override void OnDrawItem(DrawItemEventArgs e) { - base.OnDrawItem(e); - BeforeDrawItem?.Invoke(this, Items, e); if (Items.Count == 0) { @@ -857,29 +869,7 @@ namespace Sunny.UI Color foreColor = isSelected ? ItemSelectForeColor : ForeColor; Rectangle rect = new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width - 1, e.Bounds.Height - 1); - string showText; - if (DisplayMember.IsNullOrEmpty()) - { - showText = Items[e.Index].ToString(); - } - else - { - //var list = Items[e.Index].GetType().GetNeedProperties(); - //foreach (var info in list) - //{ - // if (info.Name == DisplayMember) - // { - // object defaultobj = info.GetValue(Items[e.Index], null); - // showText = defaultobj.ToString(); - // } - //} - - showText = GetItemText(Items[e.Index]); - // if (showText.IsNullOrEmpty()) - // { - // showText = Items[e.Index].ToString(); - // } - } + string showText = DisplayMember.IsNullOrEmpty() ? Items[e.Index].ToString() : GetItemText(Items[e.Index]); if (!otherState) { @@ -907,6 +897,8 @@ namespace Sunny.UI } AfterDrawItem?.Invoke(this, Items, e); + + base.OnDrawItem(e); } private Color hoverColor = Color.FromArgb(155, 200, 255);