RaUI/Source/ryControls/Sheng.Winform.Controls/ShengListView/Layout/ShengListViewDescriptiveRenderer.cs
鑫Intel c3d4ddf574 ### 2021-07-29更新
------
#### MyDbV4   V3.0.2107.2901
- *.[新增]新增支持计算文件MD5。
- *.[新增]部分DataProvider功能移植到DbExtension里,增加扩展性。
- *.[新增]UnixTimeToDateTime和JSTimeToDateTime新增支持long参数。
- *.[合并]合并RyWeb项目到MyDb里。

#### ryControlsV4    V3.0.2107.2901
  -  *.[改进]优化减少大量IDE警告和消息。
2021-07-29 17:09:32 +08:00

122 lines
3.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
namespace Sheng.Winform.Controls
{
/// <summary>
/// 为项绘制带有描述信息的渲染器
/// </summary>
public class ShengListViewDescriptiveRenderer : ShengListViewRenderer
{
#region
/// <summary>
/// 字的高度是否已初始化
/// 在第一次绘制时,测量文本的高度
/// </summary>
bool _headerHeightInited = false;
int _headerHeight;
Font _headerFont;
Size _itemPadding = new Size(8, 4);
readonly StringFormat _itemHeaderStringFormat = new StringFormat();
#endregion
#region
/// <summary>
///
/// </summary>
/// <param name="layoutManager"></param>
public ShengListViewDescriptiveRenderer(ShengListViewLayoutManager layoutManager)
: base(layoutManager)
{
layoutManager.ItemHeight = 40;
//_itemHeaderStringFormat.Alignment = StringAlignment.Center;
_itemHeaderStringFormat.FormatFlags = StringFormatFlags.LineLimit | StringFormatFlags.NoWrap;
}
#endregion
#region
internal override void DrawForeground(Graphics g)
{
}
internal override void DrawItemContent(Graphics g, Rectangle bounds, ShengListViewItem item)
{
string header = LayoutManager.GetItemText(item.Value);
//如果header为空则不南要绘制内容了
if (String.IsNullOrEmpty(header))
return;
string description = null;
if (LayoutManager.ContainerExtendMember(ShengListViewDescriptiveMembers.DescriptioinMember))
{
description = LayoutManager.GetItemText(item.Value,
LayoutManager.GetExtendMember(ShengListViewDescriptiveMembers.DescriptioinMember));
}
if (_headerHeightInited == false)
{
_headerFont = new Font(Theme.ItemHeaderFont, FontStyle.Bold);
SizeF headerSize = g.MeasureString(header, _headerFont);
_headerHeight = (int)Math.Ceiling(headerSize.Height);
_headerHeightInited = true;
}
#region
Rectangle _headerBounds = new Rectangle
{
X = _itemPadding.Width,
Y = _itemPadding.Height,//LayoutManager.ItemSize - _headerHeight - _itemPadding.Height;
Width = bounds.Width,
Height = _headerHeight
};
Rectangle _descriptionBounds = new Rectangle
{
X = _itemPadding.Width,
Y = _headerBounds.Y + _headerBounds.Height + _itemPadding.Height,
Width = bounds.Width,
Height = _headerHeight
};
//注意offset必须在最后如果先offset了_headerBounds再带入_headerBounds来计算_descriptionBounds
//就不对了
_headerBounds.Offset(bounds.Location);
_descriptionBounds.Offset(bounds.Location);
if (String.IsNullOrEmpty(header) == false)
{
using (SolidBrush brush = new SolidBrush(Theme.ItemHeaderColor))
{
g.DrawString(header, _headerFont, brush, _headerBounds, _itemHeaderStringFormat);
}
}
if (String.IsNullOrEmpty(description) == false)
{
using (SolidBrush brush = new SolidBrush(Theme.ItemDescriptioniColor))
{
g.DrawString(description, Theme.ItemHeaderFont, brush, _descriptionBounds, _itemHeaderStringFormat);
}
}
#endregion
}
#endregion
}
}