More intelligent content size checking on listview.

This commit is contained in:
Robin 2015-12-15 20:09:48 +00:00
parent a699c6341e
commit bc527a31af

View File

@ -148,7 +148,11 @@ namespace DarkUI.Controls
private void Item_TextChanged(object sender, EventArgs e) private void Item_TextChanged(object sender, EventArgs e)
{ {
UpdateContentSize(); var item = (DarkListItem)sender;
UpdateItemSize(item);
UpdateContentSize(item);
Invalidate();
} }
protected override void OnMouseDown(MouseEventArgs e) protected override void OnMouseDown(MouseEventArgs e)
@ -411,10 +415,32 @@ namespace DarkUI.Controls
highestWidth = item.Area.Right + 1; highestWidth = item.Area.Right + 1;
} }
ContentSize = new Size(highestWidth, Items.Count * ItemHeight); var width = highestWidth;
var height = Items.Count * ItemHeight;
if (ContentSize.Width != width || ContentSize.Height != height)
{
ContentSize = new Size(width, height);
Invalidate(); Invalidate();
} }
}
private void UpdateContentSize(DarkListItem item)
{
var itemWidth = item.Area.Right + 1;
if (itemWidth == ContentSize.Width)
{
UpdateContentSize();
return;
}
if (itemWidth > ContentSize.Width)
{
ContentSize = new Size(itemWidth, ContentSize.Height);
Invalidate();
}
}
public void EnsureVisible() public void EnsureVisible()
{ {