How to create RepositoryItem for a user control that takes 2 parameters to report progress?

200 views Asked by At

I have a custom user control named SegmentedProgressBar that shows progresses of threads belong to multithreaded download.I need to use in Devexpress GridControl. But I don't know how to do it and couldn't find any clear resource in my google search. I will be very appreciated if anyone can help.

I takes a Bar array and ContentLength to show progresses. ContentLength is the total length of the file in the remote source. Bar class contains 2 properties: Total partially downloaded length and start offset.

class SegmentedProgressBar : ProgressBar
{
    public SegmentedProgressBar()
    {
        ContentLength = 100;
        bars = new Bar[] { };

    Size = new Size(100, 20);
    SetStyle(ControlStyles.DoubleBuffer, true);
    SetStyle(ControlStyles.UserPaint, true);
    SetStyle(ControlStyles.AllPaintingInWmPaint, true);
    this.SizeChanged += SegmentedProgressBar_SizeChanged;
}

void SegmentedProgressBar_SizeChanged(object sender, EventArgs e)
{
    Invalidate();
}
    
    
public override Color BackColor
{
    get
    {
        return base.BackColor;
    }
    set
    {
        base.BackColor = value;
        Invalidate();
    }
}
protected override void OnPaint(PaintEventArgs e)
{
    var grp = e.Graphics;
    step = Width * 1f / contentLength;
    foreach (var br in bars.Where(x=>x.Length > 0))
    {
        var x = br.Start * step;
        var rectF = new RectangleF(x, 0,
                                br.Length * step, Height);
        grp.FillRectangle(Brushes.Blue, rectF);
    }

    base.OnPaint(e);
}

private long contentLength;
private float step;
private Bar[] bars;

public Bar[] Bars
{
    get { return bars; }
    set
    {
        bars = value;
        foreach (var element in bars)
        {
            element.PropertyChanged += element_PropertyChanged;
        }
        Invalidate();
    }
}

public long ContentLength
{
    get { return contentLength; }
    set
    {
        contentLength = value;
        step = Width * 1f / contentLength;
        Invalidate();
    }
}

private void element_PropertyChanged(object sender, EventArgs e)
{
    Invalidate();


   }
}

class Bar : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;
    public Bar(long length, long start)
    {
        this.length = length;
        this.start = start;
    }

    private long length;
    private long start;

    

    public long Start
    {
        get { return start; }

        set
        {
            var noteq = value != start;
            length = value;

            if (noteq && PropertyChanged != null)
                PropertyChanged(this, null);

        }
    }
    public long Length
    {
        get { return length; }
        set
        {
            var noteq = value != length;
            length = value;

            if (noteq && PropertyChanged != null)
                PropertyChanged(this, null);

        }
    }



}
0

There are 0 answers