Код:
}
int dg;
float x1,y1,x2,y2;
double x,y,min,max,interval;
array<float>^ a;
array<float>^ b;
Bitmap^ bmp;
Graphics^ gr;
String^ FileName;
char* StrToChar(System::String^ string) ;
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
dg1->Rows->Clear();
min=Convert::ToInt32(textBox1->Text);
max=Convert::ToInt32(textBox2->Text);
interval=Convert::ToInt32(textBox3->Text);
for(x=min;x<max;x=x+interval)
{
if (x==1)
x++;
if (x==-1)
x++;
y=sin(x)*x;
dg1->Rows->Add(x,y);
}
}
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
a = gcnew array<float>(dg->RowCount);
b = gcnew array<float>(dg->RowCount);
Pen^ p=gcnew Pen(pictureBox1->BackColor);
SolidBrush^ sb=gcnew SolidBrush(pictureBox1->BackColor);
gr->FillRectangle(sb,0,0,pictureBox1->Width,pictureBox1->Height);
a[0]=Convert::ToDouble(dg->Rows[0]->Cells[0]->Value)+pictureBox1->Width/2;
b[0]=Convert::ToDouble(dg->Rows[0]->Cells[1]->Value)+pictureBox1->Height/2;
for(int i=0;i<dg->RowCount-1;i++)
{
x1=Convert::ToDouble(dg->Rows[i]->Cells[0]->Value);
y1=Convert::ToDouble(dg->Rows[i]->Cells[1]->Value);
x2=Convert::ToDouble(dg->Rows[i+1]->Cells[0]->Value);
y2=Convert::ToDouble(dg->Rows[i+1]->Cells[1]->Value);
x1=x1+pictureBox1->Width/2;
y1=y1+pictureBox1->Height/2;
x2=x2+pictureBox1->Width/2;
y2=y2+pictureBox1->Height/2;
gr->DrawLine(Pens::Black,x1,y1,x2,y2);
a[i+1]=x2;
b[i+1]=y2;
}
pictureBox1->Image=bmp;
Drawing::Font^ drawFont = gcnew Drawing::Font("Arial", 13);
{
gr->DrawString("X",drawFont,Brushes::Black,400,150);
gr->DrawString("0",drawFont,Brushes::Black,204,135);
gr->DrawString("0",drawFont,Brushes::Black,204,10);
}
gr->DrawLine (Pens::Black,0, pictureBox1->Height/2, pictureBox1->Width,pictureBox1->Height/2);
gr->DrawLine (Pens::Black,pictureBox1->Width/2, 0, pictureBox1->Width/2,pictureBox1->Height);
for (int a=0;a<pictureBox1->Width;a+=5)
gr->DrawLine (Pens::Black,a, pictureBox1->Height/2-3,a,pictureBox1->Height/2+3);
for (int a=0;a<pictureBox1->Height;a+=5)
gr->DrawLine (Pens::Black, pictureBox1->Width/2-3,a,pictureBox1->Width/2+3,a);
}
private: System::Void openFileDialog1_FileOk(System::Object^ sender, System::ComponentModel::CancelEventArgs^ e) {
openFileDialog1->ShowDialog();
Bitmap^ bmp=gcnew Bitmap(openFileDialog1->FileName);
pictureBox1->Image=bmp;
}
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
bmp=gcnew Bitmap(pictureBox1->Width,pictureBox1->Height);
gr=Graphics::FromImage(bmp);
}
private: System::Void saveFileDialog1_FileOk(System::Object^ sender, System::ComponentModel::CancelEventArgs^ e) {
if(saveFileDialog1->ShowDialog()==Windows::Forms::DialogResult::OK)
{
String^ FileName;
FileName=saveFileDialog1->FileName;
float xtab,ytab;
FILE* f=fopen(StrToChar(FileName),"wb");
for(int i=0;i<dg1->RowCount;i++)
{
xtab=Convert::ToDouble(dg->Rows[i]->Cells[0]->Value);
ytab=Convert::ToDouble(dg->Rows[i]->Cells[1]->Value);
fwrite(&xtab,sizeof(float),1,f);
fwrite(&ytab,sizeof(float),1,f);
}
fclose(f);
}
}
};
}