我有一个表(ObjectListView),其中包含行中的音频记录。 其中一个列 - 长度格式为hh:mm:ss 我必须将BarRenderer应用于此列以显示此列中的播放进度(进度和长度)。 Shoud我写自己的渲染器还是可以使用任何现有的渲染器?
答案 0 :(得分:1)
我使用从BarRenderer派生的自定义类实现了这一点。考虑重写的Render方法。
public class BarTextRenderer : BarRenderer
{
#region Constructors
/// <summary>
/// Make a BarTextRenderer
/// </summary>
public BarTextRenderer() : base() {}
/// <summary>
/// Make a BarTextRenderer for the given range of data values
/// </summary>
public BarTextRenderer (int minimum, int maximum) : base(minimum, maximum) { }
/// <summary>
/// Make a BarTextRenderer using a custom bar scheme
/// </summary>
public BarTextRenderer (Pen pen, Brush brush) : base(pen, brush) { }
/// <summary>
/// Make a BarTextRenderer using a custom bar scheme
/// </summary>
public BarTextRenderer (int minimum, int maximum, Pen pen, Brush brush) : base(minimum, maximum, pen, brush) { }
/// <summary>
/// Make a BarTextRenderer that uses a horizontal gradient
/// </summary>
public BarTextRenderer (Pen pen, Color start, Color end) : base(pen, start, end) { }
/// <summary>
/// Make a BarTextRenderer that uses a horizontal gradient
/// </summary>
public BarTextRenderer (int minimum, int maximum, Pen pen, Color start, Color end) : base(minimum, maximum, pen, start, end) { }
#endregion
public override void Render(Graphics g, Rectangle r)
{
base.Render(g, r);
float x = r.X + (float)r.Width / 2f;
float w = r.Width/2f;
float h = Math.Max (r.Height-this.Font.Size, 0.8f*r.Height);
float y = (float)r.Y + 0.6f*(r.Height-h);
RectangleF rf = new RectangleF(x, y, w, h);
g.DrawString(this.Aspect.ToString(), this.Font, this.Brush, rf);
}
}