30 April 2016

Aplikasi Pengatur Teks



Sekarang kita mencoba menggunakan komponen lain yang terdapat ada Delphi.
Komponen yang digunakan dalam pembuatan aplikasi pengatur teks ini seperti pada gambar dibawah.

a.      Atur semua komponen seperti gambar

b.      Untuk label teks, agar memenuhi ruang GroupBoxTeks,  atur alignment (di Object Inspector) menjadi taCenter
c.       Codingnya ikuti seperti dibawah ini

unit FTeks;
interface
uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls, Vcl.ComCtrls,
  Vcl.Samples.Spin;

type
  TFormTeks = class(TForm)
    GroupBoxTeks: TGroupBox;
    LabelTeks: TLabel;
    RadioGroupWarna: TRadioGroup;
    GroupBoxJenis: TGroupBox;
    RadioButtonSansSerif: TRadioButton;
    RadioButtonComicSans: TRadioButton;
    RadioButtonCurlz: TRadioButton;
    RadioButtonLucida: TRadioButton;
    RadioButtonBook: TRadioButton;
    GroupBoxUkuran: TGroupBox;
    SpinEdit: TSpinEdit;
    GroupBox1: TGroupBox;
    CheckBoxGarisBawah: TCheckBox;
    CheckBoxMiring: TCheckBox;
    procedure RadioGroupWarnaClick(Sender: TObject);
    procedure RadioButtonSansSerifClick(Sender: TObject);
    procedure RadioButtonComicSansClick(Sender: TObject);
    procedure RadioButtonCurlzClick(Sender: TObject);
    procedure RadioButtonLucidaClick(Sender: TObject);
    procedure RadioButtonBookClick(Sender: TObject);
    procedure CheckBoxGarisBawahClick(Sender: TObject);
    procedure CheckBoxMiringClick(Sender: TObject);
    procedure SpinEditChange(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  FormTeks: TFormTeks;
implementation
{$R *.dfm}
procedure TFormTeks.CheckBoxGarisBawahClick(Sender: TObject);
begin
   with FormTeks.LabelTeks.Font do
if FormTeks.CheckBoxGarisBawah.Checked = True then
Style := Style + [fsUnderline]
else
Style := Style - [fsUnderline];

end;

procedure TFormTeks.CheckBoxMiringClick(Sender: TObject);
begin
with FormTeks.LabelTeks.Font do
if FormTeks.CheckBoxMiring.Checked = True then
Style := Style + [fsItalic]
else
Style := Style - [fsItalic];
end;

procedure TFormTeks.RadioButtonBookClick(Sender: TObject);
begin
if FormTeks.RadioButtonBook.Checked = True then
FormTeks.LabelTeks.Font.Name := 'Book Antiqua';

end;

procedure TFormTeks.RadioButtonComicSansClick(Sender: TObject);
begin
if FormTeks.RadioButtonComicSans.Checked = True then
FormTeks.LabelTeks.Font.Name := 'Comic Sans MS';
end;

procedure TFormTeks.RadioButtonCurlzClick(Sender: TObject);
begin
if FormTeks.RadioButtonCurlz.Checked = True then
FormTeks.LabelTeks.Font.Name := 'Curlz MT';
end;

procedure TFormTeks.RadioButtonLucidaClick(Sender: TObject);
begin
if FormTeks.RadioButtonLucida.Checked = True then
FormTeks.LabelTeks.Font.Name := 'Lucida Handwriting';

end;

procedure TFormTeks.RadioButtonSansSerifClick(Sender: TObject);
begin
if FormTeks.RadioButtonSansSerif.Checked = True then
FormTeks.LabelTeks.Font.Name := 'MS Sans Serif';

end;

procedure TFormTeks.RadioGroupWarnaClick(Sender: TObject);
begin
case FormTeks.RadioGroupWarna.ItemIndex of
0 :FormTeks.LabelTeks.Font.Color := clBlack;
1 :FormTeks.LabelTeks.Font.Color := clRed;
2 :FormTeks.LabelTeks.Font.Color := clBlue;
3 :FormTeks.LabelTeks.Font.Color := clYellow;
4 :FormTeks.LabelTeks.Font.Color := clGreen;
5 :FormTeks.LabelTeks.Font.Color := clPurple;
   end;

end;

procedure TFormTeks.SpinEditChange(Sender: TObject);
begin
  FormTeks.LabelTeks.Font.Size :=
  SpinEdit.Value;
end;
end.


Coba jalankan deh, semoga berhasil. 


Catatan: untuk kode kode warna bisa dilihat di Object Inpector, Color
                Untuk font, bisa mengikuti seperti yang ada di Ms Word atau yang lainnya.

Related Articles

0 komentar:

Posting Komentar