Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
пособие по программированию на ДЕЛЬФИ.doc
Скачиваний:
45
Добавлен:
11.02.2015
Размер:
1.77 Mб
Скачать

Работа 4. Создание и обработка табличных данных. Использование кнопок с фиксацией и с изображением

Для создания и обработки табличных данных используются компоненты: StringGrid и DrawGrid из страницы: Addinional, палитры компонентов. Тут же расположены кнопки: с фиксацией – SpeedButton и с изображением - BitBtn. Для размещения кнопок в качестве инструментальной панели, используется компонент ToolBar из страницы: Win32 палитры компонентов, а несколько инструментальных панелей удобней располагать в компоненте-контейнере: ControlBar из страницы: Addinional, палитры компонентов. В нижней части окна некоторых программ можно встретить информационную панель устанавливаемую с помощью компонента: StatusBar из страницы: Win32, палитры компонентов. Компонент SpinEdit расположен на странице: Samples

Пример 4а. Сконструируйте форму изображенную на рисунке.

Н

RichEdit1

апишите следующий обработчик события:OnKeyPress для RichEdit:

procedure TForm1.RichEdit1KeyPress(Sender: TObject; var Key: Char);

begin

RichEdit1.SelAttributes.Name:='Times New Roman';

if SpeedButton1.Down and SpeedButton2.Down and SpeedButton3.Down

then RichEdit1.SelAttributes.Style:=[fsBold, fsItalic, fsUnderline];

if not SpeedButton1.Down and not SpeedButton2.Down and not SpeedButton3.Down then RichEdit1.SelAttributes.Style:=[];

if SpeedButton1.Down and not SpeedButton2.Down and not SpeedButton3.Down then RichEdit1.SelAttributes.Style:=[fsBold];

if not SpeedButton1.Down and SpeedButton2.Down and not SpeedButton3.Down then RichEdit1.SelAttributes.Style:=[fsItalic];

if not SpeedButton1.Down and not SpeedButton2.Down and SpeedButton3.Down then RichEdit1.SelAttributes.Style:=[fsUnderline];

if SpeedButton1.Down and SpeedButton2.Down and not SpeedButton3.Down

then RichEdit1.SelAttributes.Style:=[fsBold, fsItalic];

if SpeedButton1.Down and not SpeedButton2.Down and SpeedButton3.Down

then RichEdit1.SelAttributes.Style:=[fsBold, fsUnderline];

if not SpeedButton1.Down and SpeedButton2.Down and SpeedButton3.Down

then RichEdit1.SelAttributes.Style:=[fsItalic, fsUnderline];

if SpeedButton4.Down then RichEdit1.Paragraph.Alignment:=taLeftJustify;

if SpeedButton5.Down then RichEdit1.Paragraph.Alignment:=taCenter;

if SpeedButton6.Down then RichEdit1.Paragraph.Alignment:=taRightJustify;

RichEdit1.SelAttributes.Size:= SpinEdit1.Value;

if SpeedButton7.Down then RichEdit1.SelAttributes.Color:=clBlack;

if SpeedButton8.Down then RichEdit1.SelAttributes.Color:=clRed;

if SpeedButton9.Down then RichEdit1.SelAttributes.Color:=clBlue;

if SpeedButton10.Down then RichEdit1.SelAttributes.Color:=clGreen;

StatusBar1.Panels[2].Text:=IntToStr(length(RichEdit1.Lines.Text));

RichEdit1.SetFocus;

end;

Пример 4б. Сконструируйте форму изображенную на рисунке.

Кол-во рабочих

10

Упражнение. Введите в таблицу ведомость зарплаты рабочих с полями: Ф.И.О, оклад, профсоюзный взнос 1%, пенсионный фонд 1%, подоходный налог 12%, к выдаче. Поля: Ф.И.О и оклад вводятся с клавиатуры, а остальные поля рассчитываются при нажатии на кнопку ОК.

Решение. Один из вариантов обработчика нажатия кнопки ОК:

procedure TForm1.BitBtn2Click(Sender: TObject);