public static String ToString(this TimeSpan timeSpan, TimeSpanStringType type)
        {
            switch (type)
            {
            case TimeSpanStringType.Full:
                return
                    (timeSpan.Days + ", " +
                     timeSpan.Hours + ":" +
                     timeSpan.Minutes + ":" +
                     timeSpan.Seconds + "," +
                     timeSpan.Milliseconds);

            case TimeSpanStringType.Normal:
                return
                    ((int)timeSpan.TotalHours + ":" +
                     timeSpan.Minutes + ":" +
                     timeSpan.Seconds);

            case TimeSpanStringType.Minimal:
                return
                    ((int)timeSpan.TotalMinutes + ":" +
                     timeSpan.Seconds);

            case TimeSpanStringType.OnlyLast:
                if (timeSpan.Days > 0)
                {
                    return(timeSpan.Days + " Days");
                }
                else if (timeSpan.Hours > 0)
                {
                    return(timeSpan.Hours + " Hours");
                }
                else if (timeSpan.Minutes > 0)
                {
                    return(timeSpan.Minutes + " Min");
                }
                else if (timeSpan.Seconds > 0)
                {
                    return(timeSpan.Seconds + " Sec");
                }
                else
                {
                    return("A little moment");
                }

            case TimeSpanStringType.Default:
                return(timeSpan.ToString());

            default:
                throw new NotImplementedException();
            }
        }
Exemple #2
0
            /// <summary>
            /// Set the time to end
            /// </summary>
            /// <param name="max">Maximum value</param>
            /// <param name="val">Value now (must be greater than 0)</param>
            /// <param name="type">Output of time</param>
            public void ShowTime(double max, double val, TimeSpanStringType type)
            {
                Form.Invoke(new Action(() =>
                {
                    if (val == 0)
                    {
                        throw new ArgumentException("Division by zero! Value cannot be 0!");
                    }

                    Form.lblTime.Text = ComputeTools.ComputeTimeToEnd(max, val,
                                                                      FirstTick, Environment.TickCount).ToString(type);
                }));
            }
 public static String ToString(this TimeSpan timeSpan, TimeSpanStringType type)
 {
     switch (type)
     {
         case TimeSpanStringType.Full:
             return
                 timeSpan.Days + ", " +
                 timeSpan.Hours + ":" +
                 timeSpan.Minutes + ":" +
                 timeSpan.Seconds + "," +
                 timeSpan.Milliseconds;
         case TimeSpanStringType.Normal:
             return
                 (int)timeSpan.TotalHours + ":" +
                 timeSpan.Minutes + ":" +
                 timeSpan.Seconds;
         case TimeSpanStringType.Minimal:
             return
                 (int)timeSpan.TotalMinutes + ":" +
                 timeSpan.Seconds;
         case TimeSpanStringType.OnlyLast:
             if (timeSpan.Days > 0)
                 return timeSpan.Days + " Days";
             else if (timeSpan.Hours > 0)
                 return timeSpan.Hours + " Hours";
             else if (timeSpan.Minutes > 0)
                 return timeSpan.Minutes + " Min";
             else if (timeSpan.Seconds > 0)
                 return timeSpan.Seconds + " Sec";
             else
                 return "A little moment";
         case TimeSpanStringType.Default:
             return timeSpan.ToString();
         default:
             throw new NotImplementedException();
     }
 }
            /// <summary>
            /// Set the time to end
            /// </summary>
            /// <param name="max">Maximum value</param>
            /// <param name="val">Value now (must be greater than 0)</param>
            /// <param name="type">Output of time</param>
            public void ShowTime(double max, double val, TimeSpanStringType type)
            {
                win.Invoke(() =>
                {
                    if (val == 0)
                        throw new ArgumentException("Division by zero! Value cannot be 0!");

                    win.Time = ComputeTools.ComputeTimeToEnd(max, val,
                        firstTick, Environment.TickCount).ToString(type);
                });
            }