Recent

Author Topic: Progress bar in stringgrid  (Read 13513 times)

Tony Stone

  • Jr. Member
  • **
  • Posts: 82
Re: Progress bar in stringgrid
« Reply #30 on: July 17, 2021, 06:15:18 pm »
you guys don't notice the incorrect displays of chars here ?

I am playing with his code sample as well.  I think it is a great idea but it doesnt exactly display as one would expect either.  I think it could work for sure... I think to make it really useful you would need to use space characters in the calculated canter of the progress to continue showing the percentage text.  And it doesnt look quite right even when i got that to partially work.  If it isn't going to take into account for the width of the cell it needs to have a character that represents the beinning and end of the 'progressbar'... so i was just playing with some characters like a | and < and > but i cant come up with much.  I do like this idea though and I think I will try and perfect my own little function of one that can be easily used in text boxes, or memos... i may learn something from it.

jamie

  • Hero Member
  • *****
  • Posts: 4841
Re: Progress bar in stringgrid
« Reply #31 on: July 17, 2021, 06:28:11 pm »
Just stick with the Custom Draw code...

If you need a little demo I can provide, because I am just one of those guys!  ::)
The only true wisdom is knowing you know nothing

Tony Stone

  • Jr. Member
  • **
  • Posts: 82
Re: Progress bar in stringgrid
« Reply #32 on: July 17, 2021, 06:35:38 pm »
Just stick with the Custom Draw code...

If you need a little demo I can provide, because I am just one of those guys!  ::)

I'm gonna hold off on the sample.  I'll seek you out when in need of a sample for something I am very stuck on! Lol...

In this case I'm gonna stick with the custom draw code.  But I love the idea of an ascii art progress bar.  Would be great for command line programs ad well I would imagine.  I'm gonna see if I can perfect a function that returns one as a string... Gonna be a little exercise for me I guess.  :D

winni

  • Hero Member
  • *****
  • Posts: 2661
Re: Progress bar in stringgrid
« Reply #33 on: July 17, 2021, 07:26:04 pm »
Hi!

Just an example with the customDraw.

I assume that the percentage has to be drawn in cells[1,1].
The percentage as a float has to be the value of cells[1,1]
As a string  for shure.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.StringGrid1DrawCell(Sender:TObject;aCol,aRow:Integer;aRect:TRect;aState: TGridDrawState);
  2.   var s : string;
  3.       ProgressRect : TRect;
  4.       percent : Single;
  5.       len,x,xd : integer;
  6. begin
  7.     if (acol=1) and (arow=1) then
  8.     begin
  9.     StringGrid1.canvas.Brush.Style:= bsSolid;
  10.     StringGrid1.canvas.Brush.color := clBlack;
  11.     StringGrid1.canvas.FillRect(aRect);
  12.     ProgressRect := aRect;
  13.     InflateRect(ProgressRect,-3,-3);
  14.     StringGrid1.canvas.Brush.color := clWhite;
  15.     StringGrid1.canvas.FillRect(ProgressRect);
  16.  
  17.     if  StringGrid1.Cells[1,1] <> '' then
  18.        percent := StrToFloat(StringGrid1.cells[1,1])
  19.        else percent := 0.0;
  20.     len := ProgressRect.Right-ProgressRect.left;
  21.     x := ProgressRect.left+ round (len * percent/100);
  22.  
  23.     StringGrid1.canvas.pen.color := clWhite;
  24.     StringGrid1.Canvas.Rectangle(ProgressRect);
  25.  
  26.     StringGrid1.canvas.Brush.color := clRed;
  27.     StringGrid1.canvas.FillRect(ProgressRect.left,ProgressRect.Top,
  28.                                             x,ProgressRect.Bottom);
  29.     s := StringGrid1.cells[1,1]+'%';
  30.     xd := (len - StringGrid1.Canvas.TextWidth(s)) div 2 +ProgressRect.left;
  31.    
  32.     StringGrid1.canvas.Brush.Style:= bsClear;
  33.     StringGrid1.canvas.TextOut(xd,ProgressRect.Top+1,s);
  34.   end;
  35. .....
  36.  
  37. end;


Winni

PS Screenshot attached
« Last Edit: July 17, 2021, 07:33:31 pm by winni »

speter

  • Full Member
  • ***
  • Posts: 222
Re: Progress bar in stringgrid
« Reply #34 on: July 18, 2021, 03:51:51 am »
you guys don't notice the incorrect displays of chars here ?

I do (Win 10, 64bit).

cheers
S.
I climbed mighty mountains, and saw that they were actually tiny foothills. :)

Laz 2.0.10 / FPC 3.2.0 / Windows 10 (64bit)

dseligo

  • Sr. Member
  • ****
  • Posts: 343
Re: Progress bar in stringgrid
« Reply #35 on: July 18, 2021, 06:07:34 am »
you guys don't notice the incorrect displays of chars here ?

I pasted code in Lazarus (2.0.10 and 2.0.12) and it looks even stranger. But when executing program it looks fine (Windows 10).

winni

  • Hero Member
  • *****
  • Posts: 2661
Re: Progress bar in stringgrid
« Reply #36 on: July 18, 2021, 10:12:08 am »
Hi!

I can't check the Windows 10 issue but it looks like this:

There is a bug in the Monotype font used by the IDE.
As this font is not used in the app there is everyhing ok.

Workaround: Use another monospaced font in the IDE.
Liberation Mono  is gentle to your eyes.

Winni

dseligo

  • Sr. Member
  • ****
  • Posts: 343
Re: Progress bar in stringgrid
« Reply #37 on: July 18, 2021, 02:35:48 pm »
Workaround: Use another monospaced font in the IDE.
Liberation Mono  is gentle to your eyes.

Same thing with Liberation Mono. I tried Source Code Pro and it shows correctly.  8)

winni

  • Hero Member
  • *****
  • Posts: 2661
Re: Progress bar in stringgrid
« Reply #38 on: July 18, 2021, 07:11:27 pm »
Hi!

Tested with different fonts including Liberation Mono on:

* Libre Office Writer
* Kate
* joe in a konsole

everything fine with Linux.

Also fine with Win7.
So it seems to be a Win10 problem.

Winni

Tony Stone

  • Jr. Member
  • **
  • Posts: 82
Re: Progress bar in stringgrid
« Reply #39 on: July 21, 2021, 02:00:47 am »
Just stick with the Custom Draw code...

If you need a little demo I can provide, because I am just one of those guys!  ::)

So I just found an issue in the code I put together with these examples here.  I am seeing odd behavior... If i have a process running that is updating the progress, then i resize my form it starts drawing the progressbar in every single cell of that column... any ideas where i should start with troubleshooting this issue?

 

TinyPortal © 2005-2018