TTMSFNCProgressBar customize value type

Good afternoon to all,
in TTMSFNCProgressBar the value type are pvtValue or pvtPercentage.
Sometime i need to show another "value" as string. For example the progress bar shows how time remain before some procedure ends. In this case the value properties increase the "progress" but while the progress's increment ... the remain time (as opposite) decrement.
There is this possibiliy in order to customize the value ?

Thank you
Daniele

Use the OnBeforeDrawValue, with this event you can draw whatever string / value you want.

Good morning Pieter,
thank you for, very fast, reply.
I tried to use that event

BeforeDrawValue(Sender: TObject; AGraphics: TTMSFNCGraphics;
  AText: string; ARect: TRectF; APosition: TTMSFNCProgressBarTextPosition;
  AOrientation: TTMSFNCProgressBarTextOrientation; var AAllow,
  ADefaultDraw: Boolean);

but Atext is always settet to "component value".

AAllow is set to true, the same for ADefaultDraw.

What happend is that AText will never change the value ... as desidered.

Can you take a look where i can do a mistake ?

Thank's

Have a nice day
Daniele

Text will not change, but nothing prevents you from drawing a custom value.

procedure TForm1.TMSFNCProgressBar1BeforeDrawValue(Sender: TObject;
  AGraphics: TTMSFNCGraphics; AText: string; ARect: TRectF;
  APosition: TTMSFNCProgressBarTextPosition;
  AOrientation: TTMSFNCProgressBarTextOrientation; var AAllow,
  ADefaultDraw: Boolean);
var
  dt: TTime;
begin
  ADefaultDraw := False;
  dt := TMSFNCProgressBar1.Value;
  AGraphics.DrawText(PointF(ARect.Left, ARect.Top), 'Time: ' + TimeToStr(dt));
end;

Hi Pieter,
thanks for reply.
You have rigth .... In this way the i can show a customize string.
Anyway this way fire up others "unwanted" behaviors.
For example:

AGraphics.DrawText(PointF(ARect.Left, ARect.Top), 'Time: ' + TimeToStr(dt));

This line write customize string according to ARect. But ARect is calculated to the component value property so, if the target is centered text, the result is not the wanted one.
Also is possible to change the start point as ARect.Left - 50 (or calculate the real center position according to string's length), in this case the text is where must be but, if are in use two fonts (one for normal show and one when text is "cover" by the progress bar) in order to get 2 color string what happend is that when the progress bar cover the text, it will be hide until the progress bar arrives to the "change color point" calculated according to component value tring. Over that point the string switch with two color.

It's possible who i miss other functions in order to get this result.
In my opinion, could be a nice feature add something like:

TTMSFNCProgressBarValueType = (pvtValue, pvtPercentage, pvtCustom);

In component.DrawValue

    if FLayout.ValueType = pvtValue then
    begin
      s :=  FLayout.Prefix + FloatToStrF(val, FLayout.TextFormat , 8 + FLayout.Decimals, FLayout.Decimals) + FLayout.Suffix;
    end
    else
    if FLayout.ValueType = pvtPercentage then
    begin
      s := FloatToStrF(perc, FLayout.TextFormat, 2 + FLayout.Decimals, FLayout.Decimals) + '%';
    end
    else
      s:=CustomString;

Where CustomString is a published string property.

I hope I wrote it well !!!!

Thank you so much for your help.

Best regards

Daniele

Hi,

We have applied your suggestion.

This will be available in the next version.

  TMSFNCProgressBar1.Layout.ValueType := pvtCustom;
  TMSFNCProgressBar1.CustomValue := 'Hello';

Hi Pieter,
thank you so much !!!

Daniele

1 Like