delphi - Draw a image in the StatusBar not working in XE7 version -
my application display informations in statusbar on initialization. i'm displaying drawing icons (on , off) on statusbar. following code works fine in embarcadero xe3, not work anymore in xe7 version. code not raise exception or errors. how can fix this?
procedure tformmain.statusbar1drawpanel(statusbar: tstatusbar; panel: tstatuspanel; const rect: trect); var i: integer; begin case panel.index of 3: begin := icon_database_off; if hasdatabaseconnection() := icon_database; imagelist1.draw(statusbar.canvas, rect.left, rect.top, i); end; 4: begin := icon_globe_off; if hasinternetconnection() := icon_globe; imagelist1.draw(statusbar.canvas, rect.left, rect.top, i); end; end; end; in xe3: 
update
(see the comments)
error occurs because onresizeevent of formmain.
procedure tformmain.formresize(sender: tobject); begin //statusbar1.panels[0].width := formmain.width - 448; statusbar1.panels[0].width := clientwidth - 448; end; the values showed when debug same in both versions:
in xe3:
formmain.width = 1400
clientwidth = 1024
in xe7:
formmain.width = 1400
clientwidth = 1024
the defined dimension 754 width , 515 height.
unknow reason, in xe7 icons not drawed.
if resize form after open, icons displayed correctly!
i not applied skin or change style of application. i'm using default configurations
the statusbar have 6 painels:
0 - show hints (width flexible; changes when form width change)
1 - show name of current selected company (fixed width)
2 - show name of current user (fixed width)
3 - show icon (fixed width)
4 - show icon (fixed width)
5 - show date (fixed width)
since painels 1~5 have fixed dimension (total = 448), not see reasons recalculate in % width of painel [0].
again, problem occurs in xe7.

you need set tpanel.style psownerdraw rather default pstext. if don't so, ondrawpanel not called.
a quick test of similar code shows works (at least in xe8):
procedure tform1.statusbar1drawpanel(statusbar: tstatusbar; panel: tstatuspanel; const rect: trect); begin if panel.index = 0 imagelist1.draw(statusbar.canvas, rect.left, rect.top, 0); end; the results:

based on comments poster (below answer), appears issue related code in form's onresize event, there no longer sufficient space 2 problem panels. code in question (taken poster's comments):
procedure tformmain.formresize(sender: tobject); begin statusbar1.panels[0].width := formmain.width - 448 ; end; first, highlight significant issue in code: never use form.width inside form's event handlers! use self.width (or width, implies self) instead, making correct code
statusbar1.panels[0].width := self.width - 448; (it better use self.clientwidth, inner (client) area of form after resize (edge) borders , scroll bars removed, rather width, btw.)
the issue panel drawing think related panel width calculation. if there not enough room panel after sizing panels[0], panels @ index 3 , 4 become small, , image drawn rectangle isn't seen. can reproduce adding event handler first code block , running app again, resizing form:
procedure tform1.formresize(sender: tobject); begin statusbar1.panels[1].width := self.width - 448; end; note change in appearance of second panel (panels1) in 2 images below - first when form displayed designed width of 800, second after reducing window 600 pixels width @ runtime.
form @ 800 pixels width - note status bar panel date:
form @ 600 pixels width - note status bar panel date missing

the solution here first deduct width of panels 3 , 4, , allocate percentage of remaining space panel 0. note i'm using form's clientwidth rather width here.
procedure tformmain.formresize(sender: tobject); var available: double; begin available := clientwidth - statusbar1.panels[3].width - statusbar1.panels[4].width; // allocate 80% of remaining width first panel statusbar1.panels[0] := trunc(available * 0.8); end;
Comments
Post a Comment