【问题标题】:Progress column with text in ObjectListViewObjectListView 中带有文本的进度列
【发布时间】:2014-02-17 23:34:28
【问题描述】:

我有一个表 (ObjectListView),其中包含行中的音频记录。 其中一列 - 格式为 hh:mm:ss 的长度 我必须将 BarRenderer 应用到此列才能在此列中显示播放进度(进度和长度)。 我应该编写自己的渲染器还是可以使用任何现有的渲染器?

【问题讨论】:

    标签: c# 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);
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-02
      • 1970-01-01
      相关资源
      最近更新 更多