Advertisement
zoltanleo

Untitled

Jul 20th, 2022
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.89 KB | None | 0 0
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. var
  3.   i: Integer;
  4. begin
  5.   FSelfFont:= TFont.Create;
  6.   FSelfFont.Assign(Screen.SystemFont);
  7.  
  8.   with lbxSize do
  9.   begin
  10.     Clear;
  11.     for i:= 8 to 20 do
  12.       if ((i mod (i div 2)) = 0) then
  13.         Items.Add(IntToStr(i));
  14.     ItemIndex:= 6;
  15.   end;
  16.  
  17.   FillLB(lbxText);
  18.   lbxSizeClick(Self);
  19. end;
  20.  
  21. procedure TForm1.btnApplyFontClick(Sender: TObject);
  22. begin
  23.   FontDialog1.Font.Assign(FSelfFont);
  24.   if FontDialog1.Execute then
  25.   begin
  26.     FSelfFont.Assign(FontDialog1.Font);
  27.     lbxSize.ItemIndex:= lbxSize.Items.IndexOf(IntToStr(FontDialog1.Font.Size));
  28.     lbxText.Repaint;
  29.   end;
  30. end;
  31.  
  32. procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
  33. begin
  34.   FSelfFont.Free;
  35. end;
  36.  
  37. procedure TForm1.lbxTextMeasureItem(Control: TWinControl; Index: Integer;
  38.   var AHeight: Integer);
  39. begin
  40.   lbxText.Canvas.Font.Assign(FSelfFont);
  41.   AHeight:= lbxText.Canvas.TextHeight(lbxText.Items[Index]);
  42.   lbxText.Repaint;
  43. end;
  44.  
  45. procedure TForm1.lbxTextDrawItem(Control: TWinControl; Index: Integer;
  46.   ARect: TRect; State: TOwnerDrawState);
  47. begin
  48.   with lbxText do
  49.   begin
  50.     Canvas.Font.Assign(FSelfFont);
  51.     Canvas.FillRect(ARect);
  52.     Canvas.TextOut(ARect.Left,ARect.Top,Items[Index]);
  53.   end;
  54. end;
  55.  
  56. procedure TForm1.lbxSizeClick(Sender: TObject);
  57. begin
  58.   FSelfFont.Size:= StrToInt(lbxSize.Items[lbxSize.ItemIndex]);
  59.   lbxText.Invalidate;
  60. end;
  61.  
  62. procedure TForm1.FillLB(Sender: TListBox);
  63. begin
  64.   with TListBox(Sender) do
  65.   begin
  66.     Clear;
  67.     Style:= lbOwnerDrawVariable;
  68.     Items.Add('abcdefghijklmnopqrstuvwxyz');
  69.     Items.Add('ABCDEFGHIJKLMNOPQRSTUVWXYZ');
  70.     Items.Add('01234567891   ўЈ¤Ґ§');
  71.     Items.Add('абвгдежзийклмнопрстуфхцшщъыь');
  72.     Items.add('АБВГДЕЖЗИЙКЛМНОПРСТУФХХШЩЪЫЬЭЯ');
  73.   end;
  74. end;
  75.  
  76. end.                                      
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement