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

Var I:integer;

begin

for i:=1 to strtoint(Edit1.Text) do

begin

StringGrid1.Cells[3,i]:=floattostr(strtofloat(StringGrid1.Cells[2,i])*0.01);

StringGrid1.Cells[4,i]:=floattostr(strtofloat(StringGrid1.Cells[2,i])*0.01);

StringGrid1.Cells[5,i]:=floattostr(strtofloat(StringGrid1.Cells[2,i])*0.12);

StringGrid1.Cells[6,i]:=floattostr(strtofloat(StringGrid1.Cells[2,i])-

strtofloat(StringGrid1.Cells[3,i])-

strtofloat(StringGrid1.Cells[4,i])-

strtofloat(StringGrid1.Cells[5,i]));

end;

end;

Работа 5. Создание и просмотр рисунков

Пример 5а. Создайте приложение для просмотра рисунков. Причем рисунок можно открыть двумя способами: 1) указав имя файла и путь в окошке и нажав кнопку «ПРОСМОТР»; 2) через главное меню: ФАЙЛ-ОТКРЫТЬ. Сконструируйте форму изображенную на рисунке.

Создайте обработчики событий OnClick

  • для кнопки «ПРОСМОТР»:

Image1.Picture.LoadFromFile(Edit1.Text);

  • для пункта главного меню: ФАЙЛ-ОТКРЫТЬ:

if OpenDialog1.Execute then Image1.Picture.LoadFromFile(OpenDialog1.FileName);

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

procedure TForm1.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;

Shift: TShiftState; X, Y: Integer);

begin

SpinEdit2.Value:=x;

SpinEdit3.Value:=y;

PaintBox1.Canvas.MoveTo(x,y);

end;

procedure TForm1.PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;

Shift: TShiftState; X, Y: Integer);

begin

PaintBox1.Canvas.Pen.Width:=SpinEdit1.Value;

if SpeedButton2.Down then PaintBox1.Canvas.LineTo(x,y);

if SpeedButton3.Down then PaintBox1.Canvas.Rectangle(SpinEdit2.Value,SpinEdit3.Value,x,y);

if SpeedButton4.Down then PaintBox1.Canvas.Ellipse(SpinEdit2.Value,SpinEdit3.Value,x,y);

end;

procedure TForm1.Button3Click(Sender: TObject);

begin

if ColorDialog1.Execute then PaintBox1.Canvas.Pen.Color:=ColorDialog1.Color;

Shape2.Pen.Color:=ColorDialog1.Color;

end;

procedure TForm1.Button4Click(Sender: TObject);

begin

if FontDialog1.Execute then begin

PaintBox1.Canvas.Font.Name:=FontDialog1.Font.Name;

PaintBox1.Canvas.Font.Style:=FontDialog1.Font.Style;

PaintBox1.Canvas.Font.Size:=FontDialog1.Font.Size;

PaintBox1.Canvas.Font.Color:=FontDialog1.Font.Color;

end;

end;

procedure TForm1.PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);

begin

StatusBar1.Panels[1].Text:=IntToStr(x);

StatusBar1.Panels[2].Text:=IntToStr(y);

end;

procedure TForm1.PaintBox1Click(Sender: TObject);

var

x, y: integer;

begin

if SpeedButton1.Down then begin

x:=StrToInt(StatusBar1.Panels[1].Text);

y:=StrToInt(StatusBar1.Panels[2].Text);

PaintBox1.Canvas.TextOut(x,y,Edit1.Text);

end;

end;

procedure TForm1.Button6Click(Sender: TObject);

begin

if ColorDialog1.Execute then

PaintBox1.Canvas.Brush.Color:=ColorDialog1.Color;

Shape1.Brush.Color:=ColorDialog1.Color;

end;

Работа 6. Работа со списками, фигурами и регуляторами

Пример 6.1. Сконструируйте форму изображенную на рисунках. В первом рисунке показаны имена компонентов, во втором их значения. Для ScrollBar1 и ScrollBar2 установите диапазон от 1 до 300.

Введите следующие обработчики событий:

procedure TForm1.ScrollBar1Change(Sender: TObject);

begin

Edit1.Text:=inttostr(ScrollBar1.Position);

Shape1.Width:=ScrollBar1.Position;

end;

procedure TForm1.ScrollBar2Change(Sender: TObject);

begin

Edit2.Text:=inttostr(ScrollBar2.Position);

Shape1.Height:=ScrollBar2.Position;

end;

procedure TForm1.ComboBox1Click(Sender: TObject);

begin

if ComboBox1.ItemIndex=0 then Shape1.Shape:=stEllipse;

if ComboBox1.ItemIndex=1 then Shape1.Shape:=stSquare;

// продолжайте

end;

procedure TForm1.ListBox1Click(Sender: TObject);

begin

if ListBox1.Selected[0] then Image1.Picture.LoadFromFile('c:\Windows\пузыри.bmp');

//продолжайте

end;

Упражнение 1. Объясните функции каждого обработчика.

Упражнение 2. Объясните работу созданной программы.