void MeasureImage(IListBoxExItem item, ref int width, ref int height) { if (item.Image == null) { return; } width = Math.Max(ItemPadding.Left + ItemPadding.Right + item.Image.Width, width); height = Math.Max(ItemPadding.Top + ItemPadding.Bottom + item.Image.Height, height); }
void MeasureCaptionSize(Graphics g, IListBoxExItem item, ref int width, ref int height) { if (item.DisplayText.IsNullOrEmpty()) { return; } var font = ShowDescription ? CaptionFont : _listControl.Font; //获得文字区最大长度,准备换行 var maxTextWidth = width - (item.Image == null ? 0 : item.Image.Width) - ImageTextSpace - ItemPadding.Left - ItemPadding.Right; var size = g.MeasureString(item.DisplayText, font, maxTextWidth > 10 ? maxTextWidth : width); var sizeDescription = SizeF.Empty; var space = 0; if (ShowDescription && !item.Description.IsNullOrEmpty()) { sizeDescription = g.MeasureString(item.Description, _listControl.Font, maxTextWidth); space = DescriptionSpace; } height = Math.Max(height, ItemPadding.Top + ItemPadding.Bottom + space + (int)size.Height + (int)sizeDescription.Height); }