Notes on First Windows In Class
The Problem
- Create a new SDI project using Application Wizard .
- Add a Draw menu with the draw circle command and a draw line command using the menu editor.. The main form should have its window state set to wsMaximize in the Object Properties window.
- Add an Image Component aligned to the main window.
- Add an event handler for each item.
Code For Event Handlers
void __fastcall TMyApplication::DrawCircleClick(TObject *Sender)
{
int x,y,radius;
String buff="";
InputQuery("Center Coordinates","Enter x, comma, y",buff);
int comma = buff.AnsiPos(",");
String intVal = buff.SubString(1,comma -1);
x = intVal.ToInt();
intVal = buff.SubString(comma+1, buff.Length() - comma);
y = intVal.ToInt();
buff = "";
InputQuery("Radius","Enter the Radius",buff);
radius = buff.ToInt();
Image1->Canvas->Brush->Color = clRed;
Image1->Canvas->Ellipse(x-radius,y-radius,x+radius, y+radius);
Image1->Canvas->Brush->Color = clWhite;
}
//---------------------------------------------------------------------------
void __fastcall TMyApplication::DrawLineClick(TObject *Sender)
{
int x1,y1,x2,y2;
String buff="";
InputQuery("First Point","Enter x, comma, y for one end of line",buff);
int comma = buff.AnsiPos(",");
String intVal = buff.SubString(1,comma -1);
x1 = intVal.ToInt();
intVal = buff.SubString(comma+1, buff.Length() - comma);
y1 = intVal.ToInt();
buff = "";
InputQuery("First Point","Enter x, comma, y for one end of line",buff);
comma = buff.AnsiPos(",");
intVal = buff.SubString(1,comma -1);
x2 = intVal.ToInt();
intVal = buff.SubString(comma+1, buff.Length() - comma);
y2 = intVal.ToInt();
buff = "";
Image1->Canvas->Pen->Color = clBlue;
Image1->Canvas->MoveTo(x1,y1);
Image1->Canvas->LineTo(x2,y2);
Image1->Canvas->Pen->Color = clBlack;
}
The Page Appearance