1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316:
| unit uResTest;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls;
type TfrmResTest = class(TForm) pnlMem: TPanel; pnlNum: TPanel; pnlFkt: TPanel; pnlDisplay: TPanel; pnlClear: TPanel; cmdMC: TButton; cmdMR: TButton; cmdMS: TButton; cmdMP: TButton; btn1: TButton; btn2: TButton; btn3: TButton; btn4: TButton; btn5: TButton; btn6: TButton; btn7: TButton; btn8: TButton; btn9: TButton; btn0: TButton; btnPluMin: TButton; btnKomma: TButton; btnSqrt: TButton; btnPro: TButton; btnBruch: TButton; btnFin: TButton; btnC: TButton; btnCE: TButton; btnBack: TButton; lblResult: TLabel; procedure FormResize(Sender: TObject); procedure pnlMemResize(Sender: TObject); procedure pnlNumResize(Sender: TObject); procedure pnlFktResize(Sender: TObject); procedure pnlDisplayResize(Sender: TObject); procedure pnlClearResize(Sender: TObject); procedure FormCreate(Sender: TObject); private function GetFontSize(iHeight, iWidth, iMargin: Integer): Integer; public end;
const Spacer = 4; iMargin = 4; var frmResTest: TfrmResTest;
implementation
{$R *.dfm}
procedure TfrmResTest.FormResize(Sender: TObject); var MemPanelWidth, NumPanelWidth, FktPanelWidth, DispPanelWidth, ClearPanelWidth, DispPanelHeight, ClearPanelHeight, MemPanelHeight : Integer; begin try try MemPanelWidth := (frmResTest.ClientWidth - (4 * Spacer)) div 10; FktPanelWidth := (frmResTest.ClientWidth - (4 * Spacer)) div 5; NumPanelWidth := frmResTest.ClientWidth - ((MemPanelWidth + FktPanelWidth) + (4 * Spacer)); DispPanelWidth := frmResTest.ClientWidth - (2*Spacer); ClearPanelWidth := frmResTest.ClientWidth - (2*Spacer); DispPanelHeight := (frmResTest.ClientHeight - (4 * Spacer)) div 10; ClearPanelHeight := (frmResTest.ClientHeight - (4 * Spacer)) div 10; MemPanelHeight := frmResTest.ClientHeight - ((DispPanelHeight + ClearPanelHeight) + (4 * Spacer)); pnlMem.Width := MemPanelWidth; pnlNum.Left := MemPanelWidth + (2 * Spacer); pnlNum.Width := NumPanelWidth; pnlNum.Top := ClearPanelHeight + DispPanelHeight + (2*Spacer); pnlNum.Height := frmResTest.ClientHeight - ((DispPanelHeight + ClearPanelHeight) + (4*Spacer)); pnlFkt.Left := MemPanelWidth + NumPanelWidth + (3 * Spacer); pnlFkt.Width := FktPanelWidth; pnlFkt.Top := ClearPanelHeight + DispPanelHeight + (2*Spacer); pnlFkt.Height := frmResTest.ClientHeight - ((DispPanelHeight + ClearPanelHeight) + (4*Spacer)); pnlDisplay.Top := Spacer; pnlDisplay.Width := DispPanelWidth; pnlClear.Top := DispPanelHeight + Spacer; pnlClear.Width := ClearPanelWidth; pnlMem.Top := DispPanelHeight + ClearPanelHeight + (2*Spacer); pnlDisplay.Height := DispPanelHeight; pnlClear.Height := ClearPanelHeight; pnlMem.Height := MemPanelHeight; except On E: Exception do ShowMessage('Error: ' + E.Message); end; finally end; end;
procedure TfrmResTest.pnlMemResize(Sender: TObject); var BtnWidth, BtnHeight, FontSize: Integer; begin BtnWidth := pnlMem.Width - (2*Spacer); BtnHeight := (pnlMem.Height - (2*Spacer)) div 4; cmdMC.Left := Spacer; cmdMR.Left := Spacer; cmdMS.Left := Spacer; cmdMP.Left := Spacer; cmdMC.Width := BtnWidth; cmdMR.Width := BtnWidth; cmdMS.Width := BtnWidth; cmdMP.Width := BtnWidth; cmdMC.Top := Spacer; cmdMR.Top := Spacer + BtnHeight; cmdMS.Top := Spacer + (2*BtnHeight); cmdMP.Top := Spacer + (3*BtnHeight); cmdMC.Height := BtnHeight; cmdMR.Height := BtnHeight; cmdMS.Height := BtnHeight; cmdMP.Height := BtnHeight; FontSize := GetFontSize(cmdMC.Height,cmdMC.Width,iMargin); cmdMC.Font.Size := FontSize; cmdMR.Font.Size := FontSize; cmdMS.Font.Size := FontSize; cmdMP.Font.Size := FontSize; end;
procedure TfrmResTest.pnlNumResize(Sender: TObject); var btnWidth, btnHeight, FontSize: Integer; begin btnWidth := (pnlNum.Width - (2*Spacer)) div 3; btnHeight := (pnlNum.Height - (2*Spacer)) div 4; btn1.Left := Spacer; btn2.Left := Spacer + btn1.Width; btn3.Left := Spacer + btn1.Width + btn2.Width; btn4.Left := Spacer; btn5.Left := Spacer + btn4.Width; btn6.Left := Spacer + btn4.Width + btn5.Width; btn7.Left := Spacer; btn8.Left := Spacer + btn7.Width; btn9.Left := Spacer + btn7.Width + btn8.Width; btn0.Left := Spacer; btnPluMin.Left := Spacer + btn0.Width; btnKomma.Left := Spacer + btn0.Width + btnPluMin.Width; btn1.Width := btnWidth; btn2.Width := btnWidth; btn3.Width := btnWidth; btn4.Width := btnWidth; btn5.Width := btnWidth; btn6.Width := btnWidth; btn7.Width := btnWidth; btn8.Width := btnWidth; btn9.Width := btnWidth; btn0.Width := btnWidth; btnPluMin.Width := btnWidth; btnKomma.Width := btnWidth; btn1.Top := Spacer; btn2.Top := Spacer; btn3.Top := Spacer; btn4.Top := Spacer + btnHeight; btn5.Top := Spacer + btnHeight; btn6.Top := Spacer + btnHeight; btn7.Top := Spacer + (2*btnHeight); btn8.Top := Spacer + (2*btnHeight); btn9.Top := Spacer + (2*btnHeight); btn0.Top := Spacer + (3*btnHeight); btnPluMin.Top := Spacer + (3*btnHeight); btnKomma.Top := Spacer + (3*btnHeight); btn1.Height := btnHeight; btn2.Height := btnHeight; btn2.Height := btnHeight; btn3.Height := btnHeight; btn4.Height := btnHeight; btn5.Height := btnHeight; btn6.Height := btnHeight; btn7.Height := btnHeight; btn8.Height := btnHeight; btn9.Height := btnHeight; btn0.Height := btnHeight; btnPluMin.Height := btnHeight; btnKomma.Height := btnHeight; FontSize := GetFontSize(cmdMC.Height,cmdMC.Width,iMargin); btn1.Font.Size := FontSize; btn2.Font.Size := FontSize; btn3.Font.Size := FontSize; btn4.Font.Size := FontSize; btn5.Font.Size := FontSize; btn6.Font.Size := FontSize; btn7.Font.Size := FontSize; btn8.Font.Size := FontSize; btn9.Font.Size := FontSize; btn0.Font.Size := FontSize; btnPluMin.Font.Size := FontSize; btnKomma.Font.Size := FontSize; end;
procedure TfrmResTest.pnlFktResize(Sender: TObject); var btnWidth, btnHeight, FontSize: Integer; begin btnWidth := pnlFkt.Width - (2*Spacer); btnHeight := (pnlFkt.Height - (2*Spacer)) div 4; btnSqrt.Left := Spacer; btnPro.Left := Spacer; btnBruch.Left := Spacer; btnFin.Left := Spacer; btnSqrt.Width := BtnWidth; btnPro.Width := BtnWidth; btnBruch.Width := BtnWidth; btnFin.Width := BtnWidth; btnSqrt.Top := Spacer; btnPro.Top := Spacer + BtnHeight; btnBruch.Top := Spacer + (2*BtnHeight); btnFin.Top := Spacer + (3*BtnHeight); btnSqrt.Height := BtnHeight; btnPro.Height := BtnHeight; btnBruch.Height := BtnHeight; btnFin.Height := BtnHeight; FontSize := GetFontSize(cmdMC.Height,cmdMC.Width,iMargin); btnSqrt.Font.Size := FontSize; btnPro.Font.Size := FontSize; btnBruch.Font.Size := FontSize; btnFin.Font.Size := FontSize; end;
procedure TfrmResTest.pnlDisplayResize(Sender: TObject); var FontSize: Integer; begin lblResult.Font.Size := GetFontSize(lblResult.Height,lblResult.Width, 0); end;
procedure TfrmResTest.pnlClearResize(Sender: TObject); var btnHeight, btnWidth, FontSize: Integer; begin btnHeight := pnlClear.Height - (2*Spacer); btnWidth := (pnlClear.Width - (2*Spacer)) div 3; btnC.Left := Spacer + btnBack.Width + btnCE.Width; btnCE.Left := Spacer + btnC.Width; btnBack.Left := Spacer; btnBack.Width := btnWidth; btnCE.Width := btnWidth; btnC.Width := btnWidth; btnBack.Top := Spacer; btnCE.Top := Spacer; btnC.Top := Spacer; btnBack.Height := btnHeight; btnCE.Height := btnHeight; btnC.Height := btnHeight; FontSize := GetFontSize(cmdMC.Height,cmdMC.Width,iMargin); btnBack.Font.Size := FontSize; btnCE.Font.Size := FontSize; btnC.Font.Size := FontSize; end;
function TfrmResTest.GetFontSize(iHeight, iWidth, iMargin: Integer): Integer; var FontSize: Integer; begin FontSize := 8; iHeight := iHeight - (2*iMargin); iWidth := iWidth - (2*iMargin); while (frmResTest.Canvas.TextWidth('MR') < iWidth) do begin Inc(FontSize); frmResTest.Canvas.Font.Size := FontSize; end; while (frmResTest.Canvas.TextHeight('MR') >= iHeight) do begin Dec(FontSize); frmResTest.Canvas.Font.Size := FontSize; end; Result := FontSize; end;
procedure TfrmResTest.FormCreate(Sender: TObject); var i: Integer; begin pnlDisplay.Top := Spacer; pnlDisplay.Left := Spacer; pnlClear.Left := Spacer; pnlMem.Left := Spacer; frmResTest.Canvas.Font := frmResTest.Font; for i := 0 to frmResTest.ControlCount-1 do begin if frmResTest.Controls[i].ClassNameIs('TButton') then begin TButton(frmResTest.Controls[i]).Font := frmResTest.Canvas.Font; end; end; end;
end. |