shape.cpp

来自「《C++ Builder 5技术内幕》一书附带的程序源代码」· C++ 代码 · 共 87 行

CPP
87
字号
//---------------------------------------------------------------------------
#include <vcl.h>
#include <TypInfo.hpp>
#pragma hdrstop

#include "Shape.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormShape *FormShape;
//---------------------------------------------------------------------------
__fastcall TFormShape::TFormShape(TComponent* Owner)
    : TForm(Owner)
{
  ShapeMain->Left = 0;
  ShapeMain->Top  = 0;
  PPropInfo PropInfo = GetPropInfo( PTypeInfo( ClassInfo( __classid( TShape ) ) ), "Shape" );
  for( int i = 0; i < 6; i++ )
    ComboBoxShape->Items->Add( GetEnumName( *(PropInfo->PropType), i ) );
}
//---------------------------------------------------------------------------
void __fastcall TFormShape::MenuItemColorShapeClick(TObject *Sender)
{
  if( ColorDialog->Execute() )
    ShapeMain->Brush->Color = ColorDialog->Color;
}
//---------------------------------------------------------------------------
void __fastcall TFormShape::MenuItemColorFormClick(TObject *Sender)
{
  if( ColorDialog->Execute() )
    FormShape->Color = ColorDialog->Color;
}
//---------------------------------------------------------------------------
void __fastcall TFormShape::ScrollBarHorizontalChange(TObject *Sender)
{
  ShapeMain->Width = ScrollBarHorizontal->Position;
}
//---------------------------------------------------------------------------
void __fastcall TFormShape::ScrollBarVerticalChange(TObject *Sender)
{
  ShapeMain->Height = ScrollBarVertical->Position;
}
//---------------------------------------------------------------------------
void __fastcall TFormShape::FormResize(TObject *Sender)
{
  ScrollBarHorizontal->Max = ClientWidth - ( ScrollBarVertical->Width + 1 );
  ScrollBarVertical->Max = ClientHeight - ( ScrollBarHorizontal->Height + 1 );
  ScrollBarHorizontal->Left = 0;
  ScrollBarVertical->Top = 0;
  ScrollBarVertical->Left = ClientWidth - ScrollBarVertical->Width;
  ScrollBarVertical->Height = ClientHeight;
  ScrollBarHorizontal->Top = ClientHeight - ScrollBarHorizontal->Height;
  ScrollBarHorizontal->Width = ClientWidth - ScrollBarVertical->Width;
}
//---------------------------------------------------------------------------
void __fastcall TFormShape::MenuItemShapesExitClick(TObject *Sender)
{
  Application->Terminate();
}
//---------------------------------------------------------------------------
void __fastcall TFormShape::MenuItemShapesRectangleClick(TObject *Sender)
{
  ShapeMain->Shape = TShapeType( dynamic_cast< TMenuItem* >( Sender )->Tag );
}
//---------------------------------------------------------------------------
void __fastcall TFormShape::MenuItemShapesRoundSquareClick(TObject *Sender)
{
  ShapeMain->Shape = TShapeType( dynamic_cast< TMenuItem* >( Sender )->Tag );
}
//---------------------------------------------------------------------------
void __fastcall TFormShape::MenuItemShapesEllipseClick(TObject *Sender)
{
  ShapeMain->Shape = TShapeType( dynamic_cast< TMenuItem* >( Sender )->Tag );
}
//---------------------------------------------------------------------------
void __fastcall TFormShape::MenuItemShapesCircleClick(TObject *Sender)
{
  ShapeMain->Shape = TShapeType( dynamic_cast< TMenuItem* >( Sender )->Tag );
}
//---------------------------------------------------------------------------
void __fastcall TFormShape::ComboBoxShapeChange(TObject *Sender)
{
  ShapeMain->Shape = TShapeType( ComboBoxShape->ItemIndex );
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?