2013-12-16 11 views
1

我有一個表(ObjectListView)與行中的音頻記錄。 其中一列 - 長度格式hh:mm:ss 我必須將BarRenderer應用到此列才能顯示此列中的播放進度(進度和長度)。 我應該寫自己的渲染器還是可以使用任何現有的渲染器?ObjectListView中的文本進度列

回答

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); 
    } 
}