Recent

Author Topic: [SOLVED] Progressbar in Statusbar rightmost panel  (Read 11293 times)

JD

  • Hero Member
  • *****
  • Posts: 1913
[SOLVED] Progressbar in Statusbar rightmost panel
« on: December 20, 2015, 04:31:08 pm »
Hi there everyone,

I'm trying to put a progressbar in the rightmost panel of a statusbar with 3 panels.

A. My first try was as follows:
Code: Pascal  [Select][+][-]
  1. procedure TfrmMain.AddProgressBarToStatusBar(Sender: TObject);
  2. var
  3.   PanelRect: TRect;
  4. begin
  5.   // Place progressbar on the statusbar
  6.   THackControl(ProgressBar1).SetParent(sbarMain);
  7.   // Retreive the rectangle of the statuspanel (in my case the second)
  8.   SendMessage(sbarMain.Handle, SB_GETRECT, 0, Integer(@PanelRect));
  9.  
  10.   // Position the progressbar over the panel on the statusbar
  11.   with PanelRect do
  12.     ProgressBar1.SetBounds(Left, Top, Right - Left, Bottom - Top + 2);
  13. end;
  14.  

I then placed AddProgressBarToStatusBar in the statusbar's OnDrawPanel.


B. My second try
I'm following the example described here - Placing a TProgressBar into a TStatusBar
http://delphi.about.com/library/weekly/aa030805a.htm

My statusbar's OnDrawPanel code is as shown below:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.StatusBar1DrawPanel(StatusBar: TStatusBar;
  2.   Panel: TStatusPanel; const Rect: TRect);
  3. begin
  4.   //
  5.   if Panel = StatusBar.Panels[3] then
  6.     with ProgressBar1 do begin
  7.       Top := Rect.Top;
  8.       Left := Rect.Left;
  9.       Width := Rect.Right - Rect.Left - 15;
  10.       Height := StatusBar1.Height - Rect.Top + 3;  //Rect.Bottom - Rect.Top;
  11.     end;
  12. end;
  13.  

In the forms' OnCreate, I put
Code: Pascal  [Select][+][-]
  1. ProgressBar1.Parent := StatusBar1;

However, in spite of all this, neither of the two tries worked. The progressbar is always shown in the first (leftmost) panel & never in the last (rightmost) panel where I want to put it.

What am I doing wrong? Thanks a lot for your assistance.

JD
« Last Edit: December 20, 2015, 07:47:17 pm by JD »
Linux Mint - Lazarus 4.6/FPC 3.2.2,
Windows - Lazarus 4.6/FPC 3.2.2

mORMot 2, PostgreSQL & MariaDB.

Never

  • Sr. Member
  • ****
  • Posts: 409
  • OS:Win7 64bit / Lazarus 1.4
Re: Progressbar in Statusbar rightmost panel
« Reply #1 on: December 20, 2015, 05:06:19 pm »
here you go try this
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormResize(Sender: TObject);
  2. const loc_MyPanel=2;{<--- change as you wish}
  3. var loc_left,loc_i:Integer;
  4.   begin
  5.    if loc_MyPanel>StatusBar1.Panels.Count then exit;
  6.   ProgressBar1.Top:=StatusBar1.Top+2{<--adjust for panel border}{make use of anchors if you do not want this line};
  7.   ProgressBar1.Height:=StatusBar1.Height-2{<--adjust for panel border}{make use of anchors if you do not want this line};
  8.    loc_left:=0;
  9.    for loc_i:=0 to loc_MyPanel do begin
  10.      loc_left:=loc_left+StatusBar1.Panels.Items[loc_i].Width;
  11.    end;
  12.    loc_left:=loc_left+loc_MyPanel;
  13.    ProgressBar1.Width:=StatusBar1.Panels.Items[loc_MyPanel].Width-2{<--adjust for panel border};
  14.    ProgressBar1.Left:=loc_left;
  15. end;
just wrote it so ...test it and convert it to procedure with apropriate params
Νέπε Λάζαρε λάγγεψων οξωκά ο φίλοσ'ς αραεύσε

JD

  • Hero Member
  • *****
  • Posts: 1913
Re: Progressbar in Statusbar rightmost panel
« Reply #2 on: December 20, 2015, 05:44:15 pm »
@Never Thanks for your reply. I tried it with both methods & it still didn't work. The progressbar is still in the first (leftmost) panel instead of the last (rightmost) panel.

JD
Linux Mint - Lazarus 4.6/FPC 3.2.2,
Windows - Lazarus 4.6/FPC 3.2.2

mORMot 2, PostgreSQL & MariaDB.

Never

  • Sr. Member
  • ****
  • Posts: 409
  • OS:Win7 64bit / Lazarus 1.4
Re: Progressbar in Statusbar rightmost panel
« Reply #3 on: December 20, 2015, 06:13:27 pm »
i'm not aware of the example you are mentioning but beyond this

i Created a new project added a statusbar,a progressbar
edit only the possition of the progressbar (set it to 30) to be able to see where it is
 and tested this ....
Code: Pascal  [Select][+][-]
  1.     procedure TForm1.FormResize(Sender: TObject);
  2.     const loc_MyPanel=2;{<--- change as you wish}
  3.     var loc_left,loc_i:Integer;
  4.       begin
  5.        if loc_MyPanel>StatusBar1.Panels.Count then exit;
  6.       ProgressBar1.Top:=StatusBar1.Top+2{<--adjust for panel border}{make use of anchors if you do not want this line};
  7.       ProgressBar1.Height:=StatusBar1.Height-2{<--adjust for panel border}{make use of anchors if you do not want this line};
  8.        loc_left:=0;
  9.        for loc_i:=0 to loc_MyPanel do begin
  10.          loc_left:=loc_left+StatusBar1.Panels.Items[loc_i].Width;
  11.        end;
  12.        loc_left:=loc_left+loc_MyPanel;
  13.        ProgressBar1.Width:=StatusBar1.Panels.Items[loc_MyPanel].Width-2{<--adjust for panel border};
  14.        ProgressBar1.Left:=loc_left;
  15.     end;

 and is working as expected
the code is pretty simple
if is not working for you something else is wrong in your project.......
 maybe forgoten anchors attached to your progressbar??
« Last Edit: December 20, 2015, 06:17:27 pm by Never »
Νέπε Λάζαρε λάγγεψων οξωκά ο φίλοσ'ς αραεύσε

balazsszekely

  • Guest
Re: Progressbar in Statusbar rightmost panel
« Reply #4 on: December 20, 2015, 06:14:40 pm »
@JD
Statusbar OwnerDraw event is only called, if you set the panel's Style property to psOwnerDraw. Do this and your code will work just fine.

JD

  • Hero Member
  • *****
  • Posts: 1913
Re: Progressbar in Statusbar rightmost panel
« Reply #5 on: December 20, 2015, 06:48:50 pm »
@JD
Statusbar OwnerDraw event is only called, if you set the panel's Style property to psOwnerDraw. Do this and your code will work just fine.

It still doesn't work. I'm missing something somewhere. Here is the example of my second try as an attachment. Thanks.

JD
Linux Mint - Lazarus 4.6/FPC 3.2.2,
Windows - Lazarus 4.6/FPC 3.2.2

mORMot 2, PostgreSQL & MariaDB.

Never

  • Sr. Member
  • ****
  • Posts: 409
  • OS:Win7 64bit / Lazarus 1.4
Re: Progressbar in Statusbar rightmost panel
« Reply #6 on: December 20, 2015, 07:11:03 pm »
told you before....!!! : )
Quote
maybe forgoten anchors attached to your progressbar??
and this is the case
edit the anchors property of the progressbar  remove the left and top anchors
and it will work
« Last Edit: December 20, 2015, 07:12:40 pm by Never »
Νέπε Λάζαρε λάγγεψων οξωκά ο φίλοσ'ς αραεύσε

JD

  • Hero Member
  • *****
  • Posts: 1913
Re: Progressbar in Statusbar rightmost panel
« Reply #7 on: December 20, 2015, 07:46:47 pm »
told you before....!!! : )
Quote
maybe forgoten anchors attached to your progressbar??
and this is the case
edit the anchors property of the progressbar  remove the left and top anchors
and it will work

Ah I see it now. You were right all along. I did not use the code you suggested for FormResize though but it still worked nonetheless.

JD
Linux Mint - Lazarus 4.6/FPC 3.2.2,
Windows - Lazarus 4.6/FPC 3.2.2

mORMot 2, PostgreSQL & MariaDB.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Progressbar in Statusbar rightmost panel
« Reply #8 on: December 20, 2015, 07:52:10 pm »
told you before....!!! : )
Quote
maybe forgoten anchors attached to your progressbar??
and this is the case
edit the anchors property of the progressbar  remove the left and top anchors
and it will work
why? What I'm missing here? Setting top+left of a control should be enough, anchors are not mend to mess with that.
« Last Edit: December 20, 2015, 07:55:56 pm by taazz »
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

JD

  • Hero Member
  • *****
  • Posts: 1913
Re: [SOLVED] Progressbar in Statusbar rightmost panel
« Reply #9 on: December 20, 2015, 08:07:22 pm »
Thanks to Never & GetMem for their suggestions. I used them to arrive at a solution.

@taazz I never imagined that the anchors could be the obstacle myself but immediately I removed them, the progressbar was placed in the rightmost panel just like I wanted it.

JD
Linux Mint - Lazarus 4.6/FPC 3.2.2,
Windows - Lazarus 4.6/FPC 3.2.2

mORMot 2, PostgreSQL & MariaDB.

Never

  • Sr. Member
  • ****
  • Posts: 409
  • OS:Win7 64bit / Lazarus 1.4
Re: [SOLVED] Progressbar in Statusbar rightmost panel
« Reply #10 on: December 20, 2015, 09:14:42 pm »
@JD glad you made it
@ taazz
Quote
why? What I'm missing here? Setting top+left of a control should be enough, anchors are not mend to mess with that.
why not? isn't this the purpose of anchors?to force bounds and position?
[Edit]@ taazz,
 whenever a new control is added on a form left and top anchors are checked by default and this produces this kind of problems as JD's one
« Last Edit: December 20, 2015, 09:32:10 pm by Never »
Νέπε Λάζαρε λάγγεψων οξωκά ο φίλοσ'ς αραεύσε

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: [SOLVED] Progressbar in Statusbar rightmost panel
« Reply #11 on: December 20, 2015, 09:49:16 pm »
@JD glad you made it
why not? isn't this the purpose of anchors?to force bounds and position?

No the anchors are there to keep the control in place when the form is resized, what place is that, depends on the anchors, setting left and top properties has nothing to do with the anchors, the position should change as the code dictates, if not, then there is a bug.

[Edit]@ taazz,
 whenever a new control is added on a form left and top anchors are checked by default and this produces this kind of problems as JD's one
checked how? What a check will force the left and top to be set to 0,0 every time they are changed?

I'm not refuting the observed results I'm asking why they are produced. This sounds like an unacceptable behavior.
In any case thank you for your time. Weird behavior noted.
« Last Edit: December 20, 2015, 09:57:04 pm by taazz »
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Never

  • Sr. Member
  • ****
  • Posts: 409
  • OS:Win7 64bit / Lazarus 1.4
Re: [SOLVED] Progressbar in Statusbar rightmost panel
« Reply #12 on: December 20, 2015, 09:57:09 pm »
Quote
I'm not refuting the observed results I'm asking why they are produced. Seems that you haven't delved in to the problem your self either. This is unacceptable behavior if I where you I would report a bug. In any case thank you for your time. I'll add it to my lcl weird things list.
@taazz,
Quote
delved in to the problem your self either
no taazz i didn't (lol)
 i stopped a long time ago to search whys and report bugs.... i just make things work
Quote
if I where you I would report a bug
no thank you very much sir if you like you are wellcome to do so
(lolol)
Νέπε Λάζαρε λάγγεψων οξωκά ο φίλοσ'ς αραεύσε

Never

  • Sr. Member
  • ****
  • Posts: 409
  • OS:Win7 64bit / Lazarus 1.4
Re: [SOLVED] Progressbar in Statusbar rightmost panel
« Reply #13 on: December 20, 2015, 10:48:18 pm »
@taazz,
you removed the insulting part of your message thats a nice step....thank you...
after all i do not see oracles and solve problems do i? lololol
Quote
No the anchors are there to keep the control in place when the form is resized,
this is not completely true they are doing more
ref [ http://wiki.lazarus.freepascal.org/Anchor_Sides ]
have a look at [ Anchoring to invisible controls ]
and trace Setbounds,ChangeBounds,UpdateAnchorRules,UpdateBaseBounds  you will have your answer.
Quote
checked how?
just add some controls on a form and open anchors editor for each one of them

see you next time i will be around
Νέπε Λάζαρε λάγγεψων οξωκά ο φίλοσ'ς αραεύσε

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: [SOLVED] Progressbar in Statusbar rightmost panel
« Reply #14 on: December 20, 2015, 11:00:34 pm »
@taazz,
you removed the insulting part of your message thats a nice step....thank you...
after all i do not see oracles and solve problems do i? lololol

I did? Sorry I wasn't aware I was insulting you, I was only trying to state facts. To not delve in the inner workings of tstatusbar is expected, there is nothing to learn, nothing to gain either and on top of that it is a considerable waste of time. I haven't delved in those details either. If my statement showed anything it probably was my disappointment that now I have to spend this time on those details, especially since for the time being I'm not going to upgrade lazarus beyond 1.4.4. 

Quote
No the anchors are there to keep the control in place when the form is resized,
this is not completely true they are doing more
ref [ http://wiki.lazarus.freepascal.org/Anchor_Sides ]
have a look at [ Anchoring to invisible controls ]
and trace Setbounds,ChangeBounds,UpdateAnchorRules,UpdateBaseBounds  you will have your answer.
Quote
checked how?
just add some controls on a form and open anchors editor for each one of them
Wrong anchors. Those seem to be the "new" layout engine that help you attach one control to the side of the other they should be independent from the anchors property.
see you next time i will be around
Have fun.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

 

TinyPortal © 2005-2018