Synchronous ProgressBar

In Eyeshot 9 the ProgressBar can be used only in asynchronous WorkUnits (the ones ran with viewportLayout.StartWork()).

In case you want to use the ProgressBar in a synchronous way, independently from the WorkUnits, updating its value when needed and then calling Invalidate(), you can use this trick:

Derive the ProgressBar class and expose its Draw method:

       public class MyProgressBar : devDept.Eyeshot.ProgressBar
        {
            public MyProgressBar()
            {
                Visible = false;
            }

            public void Draw(ViewportLayout.DrawSceneParams myParams)
            {
                base.Draw(myParams);
            }
        }

 

Derive the ViewportLayout and draw the custom progress bar in the DrawOverlay method:

 internal class MyViewportLayout : devDept.Eyeshot.ViewportLayout
 {  
        public MyProgressBar myProgr = new MyProgressBar(); 
protected override void DrawOverlay(DrawSceneParams data) { base.DrawOverlay(data); if (myProgr.Visible) {
data.Viewport = Viewports[ActiveViewport]; myProgr.Draw(data); } } }

 

Create the viewportLayout1 control as an instance of the MyViewportLayout class:

 

this.viewportLayout1 = new MyViewportLayout();

 

Somewhere in your code enable/disable the custom ProgressBar and update its value:

            var myProgr = ((MyViewportLayout) viewportLayout1).myProgr;
            if (!myProgr.Visible)
            {
                myProgr.Text = "Processing...";
                myProgr.Visible = true;
                myProgr.Value = 0;
            }
            else if (myProgr.Value == 100)
            {
                myProgr.Value = 0;
                myProgr.Visible = false;
            }

            if (myProgr.Visible)
                myProgr.Value += 10;

            viewportLayout1.Invalidate();
Have more questions? Submit a request

2 Comments

  • 0
    Avatar
    Damian Rafferty

    How do you set the max value of the progress bar calculate the increment value?

    Edited by Damian Rafferty
  • 0
    Avatar
    Damian Rafferty

    Realised that you can calculate the value as a percentage.

    private int Progress(int count, int value, int total)
    {
        return (int)((double)count / total * 100);
    }

Please sign in to leave a comment.