
3 Текст программы
private: System::Void button_Close_Click(System::Object^sender,System::EventArgs^ e) {
this->Close();
}
//начальные значения при старте формы
void MyForm_Load(System::Object^ sender, System::EventArgs^ e)
{
this->lblCourse->Text = L"Курс покупки";
}
private:
double rubToDollar; //глобальные переменные для курсов
double rubToEuro;
double dollarToRub;
double euroToRub;
bool chek = false;
//различные обработки при нажатии кнопок
void keyPress(System::Windows::Forms::TextBox^ txt, System::Windows::Forms::KeyPressEventArgs^ e)
{
char key = e->KeyChar;
if (Char::IsDigit(e->KeyChar) || key == 8 || key == '.')
{
if (key == '.')
{
for (int i = 0; i < txt->Text->Length; ++i)
{
if (txt->Text[i] == '.')
{
e->Handled = true;
}
}
int PointPos = 0;
if (txtAmount->Text != "" && txtAmount->Text[0] != '0')
{
PointPos = 1;
}
if (txt->Text->IndexOf('.') == -1 && txt->Text->IndexOf('0') == -1 && txt->SelectionStart == PointPos)
{
txt->Text = txt->Text->Insert(PointPos, "0");
txt->SelectionStart = PointPos + 1;
txt->SelectionStart = txt->Text->Length;
}
if (txt->SelectionStart > txt->Text->IndexOf('.') + 2 && txt- >Text->IndexOf('.') != -1)
{
if (key != 8)
{
e->Handled = true;
}
}
if (key == '0' && txt->Text->Length == 1 && txt->Text[0] == '0') {
e->Handled = true;
}
if (txt->Text->Length == 1)
{
e->Handled = true;
}
}
else
{
e->Handled = true;
}
}
private: System::Void txtAmount_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e)
{
if ((e->KeyChar != (char)8) && (e->KeyChar != (char)44) && (e->KeyChar != (char)45) && (e->KeyChar < (char)48 || e->KeyChar >(char)57))
{
e->Handled = true;
}
}
private: System::Void txtCourse_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e)
{
if ((e->KeyChar != (char)8) && (e->KeyChar != (char)44) && (e->KeyChar != (char)45) && (e->KeyChar < (char)48 || e->KeyChar >(char)57))
{
e->Handled = true;
}
}
//нажатие кнопки "конвертировать"
private: System::Void button_Convert_Click(System::Object^ sender, System::EventArgs^ e)
{
double a, i, s, k, r, ev, d;
if (this->txtAmount->Text->Length == 0 || this->txtCourse->Text->Length == 0)
{
MessageBox::Show("Введите все исходные данные!");
}
else if ((a = System::Double::Parse(txtAmount->Text)) < 0.1)
{
MessageBox::Show("Сумма конвертации слишком мала!");
}
else if (chek) {
s = System::Double::Parse(txtAmount->Text);
k = System::Double::Parse(txtCourse->Text);
int i = 1;
switch (i)
{
case 1:
r = s * k;
this->txtAmount2->Text = Convert::ToString(s);
this->txtResult->Text = Convert::ToString(r);
break;
case 2:
r = s / k;
this->txtAmount2->Text = Convert::ToString(s);
this->txtResult->Text = Convert::ToString(r);
break;
case 3:
r = s * k;
this->txtAmount2->Text = Convert::ToString(s);
this->txtResult->Text = Convert::ToString(r);
break;
case 4:
r = s / k;
this->txtAmount2->Text = Convert::ToString(s);
this->txtResult->Text = Convert::ToString(r);
break;
}
}
else { MessageBox::Show("Выберите направление конвертации!"); }
}
//изменение направления конвертации
void RadioButton_CheckedChanged(double course, String^ sign, int type)
{
chek = true;
if (!course == 0)
{
this->txtCourse->Text = L"" + course;
}
else
{
this->txtCourse->Text = L"";
}
this->lblError->Text = L"";
this->txtAmount->Text = L"";
this->txtAmount2->Text = L"";
this->txtResult->Text = L"";
this->lblMoneyUnit1->Text = L"";
this->lblMoneyUnit2->Text = L"";
this->lblCourseSign->Text = L"" + sign + ":";
}
//направление конвертации «Рубли в Доллары»
private: System::Void RubToDollar_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
{
chek = true;
double i, ev, d;
this->lblMoneyUnit1->Text = L"руб =";
this->lblMoneyUnit2->Text = L"$";
this->lblError->Text = L"";
this->txtAmount2->Text = L"";
this->txtResult->Text = L"";
this->lblCourse->Text = L"Курс покупки";
this->lblCourseSign->Text = L"(руб / $):";
i = 2;
}
//направление конвертации «Доллары в Рубли»
private: System::Void DollarToRub_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
{
chek = true;
double i, ev, d;
this->lblMoneyUnit1->Text = L"$ =";
this->lblMoneyUnit2->Text = L"руб.";
this->lblError->Text = L"";
this->txtAmount2->Text = L"";
this->txtResult->Text = L"";
this->lblCourse->Text = L"Курс продажи";
this->lblCourseSign->Text = L"($ / руб):";
i = 1;
}
//направление конвертации «Рубли в Евро»
private: System::Void RubToEuro_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
{
chek = true;
double i, ev, d;
this->lblMoneyUnit1->Text = L"руб =";
this->lblMoneyUnit2->Text = L"€";
this->lblError->Text = L"";
this->txtAmount2->Text = L"";
this->txtResult->Text = L"";
this->lblCourse->Text = L"Курс покупки";
this->lblCourseSign->Text = L"(руб / €):";
i = 4;
}
//направление конвертации «Евро в Рубли»
private: System::Void EuroToRub_CheckedChanged(System::Object^ sender, System::EventArgs^ e)
{
chek = true;
double i, ev, d;
this->lblMoneyUnit1->Text = L"€ =";
this->lblMoneyUnit2->Text = L"руб.";
this->lblError->Text = L"";
this->txtAmount2->Text = L"";
this->txtResult->Text = L"";
this->lblCourse->Text = L"Курс продажи";
this->lblCourseSign->Text = L"(€ / руб):";
i = 3;
}
//изменение суммы конвертации
private: System::Void txtAmount_TextChanged(System::Object^ sender, System::EventArgs^ e)
{
this->lblError->Text = L"";
this->txtAmount2->Text = L"";
this->txtResult->Text = L"";
}
//изменение курса конвертации
private: System::Void txtCourse_TextChanged(System::Object^ sender, System::EventArgs^ e)
{
this->lblError->Text = L"";
this->txtAmount2->Text = L"";
this->txtResult->Text = L"";
}
};
}