📄 unit3.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit3.h"
#include "Basic_graph.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm3 *Form3;
//---------------------------------------------------------------------------
__fastcall TForm3::TForm3(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
#define LEFT 1
#define RIGHT 2
#define BOTTOM 4
#define TOP 8
void __fastcall TForm3::Button1Click(TObject *Sender)
{
Form3->Close();
//Image1->Canvas->Pen->Color = clRed;
//Form1->Image1->Canvas->Pen->Color = clWhite;
int xmin,ymin,xmax,ymax;
float x,y,x1,y1,x2,y2,k;
xmin=StrToFloat(Edit1->Text);
ymin=StrToFloat(Edit2->Text);
xmax=StrToFloat(Edit3->Text);
ymax=StrToFloat(Edit4->Text);
x1=StrToFloat(Edit5->Text);
y1=StrToFloat(Edit6->Text);
x2=StrToFloat(Edit7->Text);
y2=StrToFloat(Edit8->Text);
Form1-> Image1->Canvas->Pen->Color = clRed;
Form1-> Image1->Canvas->MoveTo(xmin,ymin);
Form1-> Image1->Canvas->LineTo(xmin,ymax);
Form1-> Image1->Canvas->LineTo(xmax,ymax);
Form1-> Image1->Canvas-> LineTo(xmax,ymin);
Form1-> Image1->Canvas->LineTo(xmin,ymin); //窗口
Form1->Image1->Canvas->Pen->Color=clBlack;
//Image1->Canvas->Pen->Mode=pmXor;
Form1-> Image1->Canvas->MoveTo(x1,y1);
Form1-> Image1->Canvas->LineTo(x2,y2);
{
if(x=xmax)
{
y=(x2*y1-x1*y2+(y2-y1)*x)/(x2-x1);
if(y!=0)
{
Form1-> Image1->Canvas->Pen->Color = clRed;
Form1-> Image1->Canvas->MoveTo(xmax,y);
Form1-> Image1->Canvas->LineTo(x2,y2);
}
}
if(x=xmin)
{
y=(x2*y1-x1*y2+(y2-y1)*x)/(x2-x1);
if(y!=0)
{
Form1-> Image1->Canvas->Pen->Color = clRed;
Form1-> Image1->Canvas->MoveTo(xmin,y);
Form1-> Image1->Canvas->LineTo(x1,y1);
}
}
if(y=ymax)
{
x=(x2*y1-x1*y2+(x1-x2)*y)/(y1-y2);
if(x!=0)
{
if(y1>ymax)
{
Form1-> Image1->Canvas->Pen->Color = clRed;
Form1-> Image1->Canvas->MoveTo(x,ymax);
Form1-> Image1->Canvas->LineTo(x1,y1);
}
else
{
Form1-> Image1->Canvas->Pen->Color = clRed;
Form1-> Image1->Canvas->MoveTo(x,ymax);
Form1-> Image1->Canvas->LineTo(x2,y2);
}
}
}
if(y=ymin)
{
x=(x2*y1-x1*y2+(x1-x2)*y)/(y1-y2);
if(x!=0)
{
if(y1<ymin)
{
Form1-> Image1->Canvas->Pen->Color = clRed;
Form1-> Image1->Canvas->MoveTo(x,ymin);
Form1-> Image1->Canvas->LineTo(x1,y1);
}
else
{
Form1-> Image1->Canvas->Pen->Color = clRed;
Form1-> Image1->Canvas->MoveTo(x,ymin);
Form1-> Image1->Canvas->LineTo(x2,y2);
}
}
}
}
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -