回 帖 发 新 帖 刷新版面

主题:请问为什么?(初学者)

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
#include<math.h>
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{  Canvas->Pen->Color=clTeal;
   Canvas->Brush->Style=bsClear;
double AL,x1,y1,x2,y2;
int L=120;
for(int i=0;i<48;i++)
AL=i*M_PI/24;
x1=L*cos(AL);
y1=L*sin(AL);
x2=x1+320;
y2=-y1+240;
Canvas->Ellipse(x2-90,y2-90,x2+90,y2+90);

}

我看了别人写的文章,怎么我写的不能绘出图形?

回复列表 (共6个回复)

沙发

上述代码写在TForm1的OnPaint事件里面

板凳


#include <vcl.h>
#pragma hdrstop
#include<math.h>
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)
{ double AL,x1,y1,x2,y2;
int L=120;
for(int i=0;i<48;i++)
{ AL=i*M_PI/24;
x1=L*cos(AL);
y1=L*sin(AL);
x2=x1+320;
y2=y1+240;
Canvas->Brush->Style=bsClear;
}
  Width=640;
   Height=480;
   Canvas->Pen->Color=clTeal;
   Canvas->Brush->Style=bsClear;
}
//这样,编译能通过,为什么在form上看不见画的图呢,打击死我了!!!

3 楼

你把笔的颜色变一下试试看。

4 楼

christ115 说得对,应该写在OnPaint事件中~

5 楼

呵呵 ,我也不清楚怎么回事

6 楼

函數Ellipse應該寫在For循環語句中:

void __fastcall TForm1::FormPaint(TObject *Sender)
{
        double AL,x1,y1,x2,y2;
        int L=120;
        for(int i=0;i<48;i++)
           {
             AL=i*M_PI/24;
             x1=L*cos(AL);
             y1=L*sin(AL);
             x2=x1+320;
             y2=y1+240;
             Canvas->Brush->Style=bsClear;
             Canvas->Ellipse(x1-90,y1-90,x2+90,y2+90);
            }
        Width=640;
        Height=480;
        Canvas->Pen->Color=clRed;
        Canvas->Brush->Style=bsClear;

}

我来回复

您尚未登录,请登录后再回复。点此登录或注册