First a little background. I didn't find the TChartPreviewer component suitable for my program. It has a number of unnecessary controls for my purposes. Also, I don't like that it is a modal form -- I would have preferred a panel embedded in my own form. Therefore, I am trying to make use of the TTeePreviewPanel, which I can embed nicely into my form.
The TTeePreviewPanel has no controls other than the chart preview itself and some draggable margins. Therefore, I have to add the controls I need.
I have added four spin edit controls for setting the print margins. I have set TeePreviewPanel1.PrintProportional = True. The question is, how to adjust the print margins when one of my fours spin edits is changed? It appears that it is not as simple as transferring the spin edit values to the TeePreviewPanel1.PrintMargins rectangle because of the PrintProportional constraint. It appears that the function CalcProportionalMargins comes into it somewhere, but I cannot figure out how to do it! Help please!
Setting proportional print margins with TTeePreviewPanel
-
- Newbie
- Posts: 29
- Joined: Tue Oct 13, 2015 12:00 am
Re: Setting proportional print margins with TTeePreviewPanel
Hello,
I think you'll need to code this yourself taking the Chart proportions and re-applying them.
I tried this with an updown button and it seems to work ok (just controlling and on-applying the left margin here). This example would have a Chart and a TeePreviewPanel on a form.
Declared some variables outside the working procedure at form level:
Set Updown value on form open plus one-entry flag for some init code.
and put code in updown click:
Regards,
Marc Meumann
I think you'll need to code this yourself taking the Chart proportions and re-applying them.
I tried this with an updown button and it seems to work ok (just controlling and on-applying the left margin here). This example would have a Chart and a TeePreviewPanel on a form.
Declared some variables outside the working procedure at form level:
Code: Select all
var
Form1: TForm1;
startBottomMargin, startTopMargin, startLeftMargin, startRightMargin: Integer;
Code: Select all
UpDown2.Position := Chart1.PrintMargins.Left;
startBottomMargin := -1;
Code: Select all
procedure TForm1.UpDown2Click(Sender: TObject; Button: TUDBtnType);
Var Delta : Integer;
horizDiff, currentHeightProportion, newHeightProportion : Double;
procedure ResetProportion;
Begin
Chart1.PrintMargins.Right := startRightMargin + Delta;
horizDiff := (Chart1.PrintMargins.Right+Chart1.PrintMargins.Left) / (startRightMargin+startLeftMargin);
//apply % to height
currentHeightProportion := 100 - (startTopMargin+startBottomMargin);
newHeightProportion := currentHeightProportion / horizDiff;
//set Heightmargins
Chart1.PrintMargins.Top := Round( (100-newHeightProportion) / 2);
Chart1.PrintMargins.Bottom := Round( (100 - newHeightProportion) / 2);
end;
begin
if startBottomMargin = -1 then
Begin
startBottomMargin :=Chart1.PrintMargins.Bottom;
startTopMargin :=Chart1.PrintMargins.Top;
startLeftMargin :=Chart1.PrintMargins.Left;
startRightMargin :=Chart1.PrintMargins.Right;
end;
Chart1.PrintProportional := False;
Chart1.PrintMargins.Left:= UpDown2.Position;
Delta := Chart1.PrintMargins.Left - startLeftMargin;
ResetProportion;
TeePreviewPanel1.Repaint;
end;
Marc Meumann
Steema Support
-
- Newbie
- Posts: 29
- Joined: Tue Oct 13, 2015 12:00 am
Re: Setting proportional print margins with TTeePreviewPanel
Thank you! That was so helpful.