概要:別ウインドを用い、三角関数を計算する。
メインウインドのラジオボックスでsin/cos/tanを選択し、「設定」ボタンで現れる別ウインドで値[rad]を入力、[OK]ボタンを押すとメインウインドに結果が表示される。
<作業>
1.フォームを追加
2.フォーム1にRadioGroupを置き、Editで"sin/cos/tan"を選べるようにする。
3.フォーム1にビットマップボタンbkCloseを置く。
4.Labelを使ってメインウインドに"Ans="と書く。
5.Panelを配置し、Nameをansにする。
6.フォーム2にパーツを置き、プロパティ設定。
Panelを置き、Nameはfunc Editを置き、Text は" "(なし)、Taborderは0 ビットマップボタンを2個置き、KindはbkOkとbkCancelに。
//--------------------------------------------------------------------------- #include#pragma hdrstop #include "Usamp51.h" //--------------------------------------------------------------------------- #pragma resource "*.dfm" #include "Usamp512.cpp" #include "math.h" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- float Henkan(int f) { float ans; switch(f) { case 0: ans=sin(StrToFloat(Form2->Edit1->Text)); break; case 1: ans=cos(StrToFloat(Form2->Edit1->Text)); break; case 2: ans=tan(StrToFloat(Form2->Edit1->Text)); break; } return(ans); } void __fastcall TForm1::Button1Click(TObject *Sender) { int x; x=RadioGroup1->ItemIndex; switch(x) { case 0: Form2->func->Caption="sin";break; case 1: Form2->func->Caption="cos";break; case 2: Form2->func->Caption="tan";break; } int Val=Form2->ShowModal(); if(Val==mrOk) { float ans,ans2; ans2=Henkan(StrToInt(RadioGroup1->ItemIndex)); Form1->ans->Caption=FloatToStr(ans2); } } //---------------------------------------------------------------------------