RaUI/Source/ryControls/Sheng.Winform.Controls/ShengListView/Layout/ShengListViewStandardRenderer.cs
鑫Intel 8b41f58f5c ### 2021-07-01更新
------
#### ryControlsV4    V3.0.2107.0101
- *.[新增]新增Sheng.Winform.Controls部分控件。

#### RyWeb    V3.0.2107.0101
- *.[新增]QuickWeb新增引用页设置。
#### MyDbV4    V3.0.2107.0101
- *.[新增]支持忽略大小写的替换功能。
2021-07-04 09:41:31 +08:00

86 lines
2.5 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>
/// 默认渲染器以类似微软ListView的方式按行绘制项只绘制简单的文本
/// </summary>
class ShengListViewStandardRenderer : ShengListViewRenderer
{
#region
/// <summary>
/// 字的高度是否已初始化
/// 在第一次绘制时,测量文本的高度
/// </summary>
bool _headerHeightInited = false;
int _headerHeight;
Size _itemPadding = new Size(8, 4);
Rectangle _headerBounds;
StringFormat _itemHeaderStringFormat = new StringFormat();
#endregion
#region
public ShengListViewStandardRenderer(ShengListViewLayoutManager layoutManager)
: base(layoutManager)
{
layoutManager.ItemHeight = 24;
//_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);
if (String.IsNullOrEmpty(header))
return;
if (_headerHeightInited == false)
{
SizeF headerSize = g.MeasureString(header, Theme.ItemHeaderFont);
_headerHeight = (int)Math.Ceiling(headerSize.Height);
_headerHeightInited = true;
}
#region
_headerBounds = new Rectangle();
_headerBounds.X = _itemPadding.Width;
_headerBounds.Y = _itemPadding.Height;
_headerBounds.Width = bounds.Width;
_headerBounds.Height = _headerHeight;
_headerBounds.Offset(bounds.Location);
if (String.IsNullOrEmpty(header) == false)
{
using (SolidBrush brush = new SolidBrush(Theme.ItemHeaderColor))
{
g.DrawString(header, Theme.ItemHeaderFont, brush, _headerBounds, _itemHeaderStringFormat);
}
}
#endregion
}
#endregion
}
}