Лабораторные работы: пятнашки и редактор фигур
This commit is contained in:
commit
a5dbf9d3a2
1 changed files with 2579 additions and 0 deletions
66
BoundsUnit.cpp
Normal file
66
BoundsUnit.cpp
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
#include <vcl.h>
|
||||
#pragma hdrstop
|
||||
|
||||
#include "BoundsUnit.h"
|
||||
|
||||
#pragma package(smart_init)
|
||||
#pragma resource "*.dfm"
|
||||
TfrmBounds *frmBounds;
|
||||
|
||||
__fastcall TfrmBounds::TfrmBounds(TComponent* Owner) : TForm(Owner)
|
||||
{
|
||||
}
|
||||
|
||||
// TUpDown при показе пишет в поле свой Position, поэтому ставим и то и другое
|
||||
void TfrmBounds::Put(TEdit *e, TUpDown *ud, int v)
|
||||
{
|
||||
ud->Position = v;
|
||||
e->Text = IntToStr(v);
|
||||
}
|
||||
|
||||
// показать окно; true - если нажали OK и фигура изменена
|
||||
bool TfrmBounds::Edit(TFigure *f)
|
||||
{
|
||||
lblFigure->Caption = f->RusName() + L" №" + IntToStr(f->GetNum());
|
||||
Put(edtX, udX, f->GetX());
|
||||
Put(edtY, udY, f->GetY());
|
||||
Put(edtW, udW, f->GetW());
|
||||
Put(edtH, udH, f->GetH());
|
||||
// по центру окна, из которого открыли
|
||||
TForm *parent = Screen->ActiveForm;
|
||||
if (parent)
|
||||
{
|
||||
Left = parent->Left + (parent->Width - Width) / 2;
|
||||
Top = parent->Top + (parent->Height - Height) / 2;
|
||||
}
|
||||
ActiveControl = edtX;
|
||||
if (ShowModal() != mrOk)
|
||||
return false; // "Отмена" - фигура не меняется
|
||||
f->SetBounds(StrToInt(edtX->Text), StrToInt(edtY->Text),
|
||||
StrToInt(edtW->Text), StrToInt(edtH->Text));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TfrmBounds::Valid(TEdit *e, String what, int a, int b)
|
||||
{
|
||||
int v;
|
||||
if (TryStrToInt(e->Text.Trim(), v) && v >= a && v <= b)
|
||||
{
|
||||
e->Text = IntToStr(v);
|
||||
return true;
|
||||
}
|
||||
String msg = what + L" - введите целое число от " + IntToStr(a) + L" до " + IntToStr(b) + L".";
|
||||
Application->MessageBox(msg.c_str(), L"Неверное значение", MB_OK | MB_ICONWARNING);
|
||||
e->SetFocus();
|
||||
e->SelectAll();
|
||||
return false;
|
||||
}
|
||||
|
||||
void __fastcall TfrmBounds::btnOkClick(TObject *Sender)
|
||||
{
|
||||
if (!Valid(edtX, "X", POS_MIN, POS_MAX)) return;
|
||||
if (!Valid(edtY, "Y", POS_MIN, POS_MAX)) return;
|
||||
if (!Valid(edtW, L"Ширина", SIDE_MIN, SIDE_MAX)) return;
|
||||
if (!Valid(edtH, L"Высота", SIDE_MIN, SIDE_MAX)) return;
|
||||
ModalResult = mrOk;
|
||||
}
|
||||
Loading…
Reference in a new issue