segunda-feira, 20 de julho de 2020

FMX - Imprimindo tabuada

Criar uma tabuada em C ou C++ é tarefa muito fácil,
qualquer iniciante pode fazer, mas esta aqui usa 
uma janela gráfica feita no C++ Builder da Embarcadero,
acompanhem seu funcionamento no vídeo abaixo:



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

#include <fmx.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
int x;
//---------------------------------------------------------------------------
void __fastcall TForm1::Label_Manual ( TObject *Sender ) {
   Edit1 -> SetFocus ( );
   Edit1 -> Font -> Size = 10;
   Edit1 -> Width = 90;
   Edit1 -> Height = 20;
   Edit1 -> Position -> X = 180;
   Edit1 -> Position -> Y = 70;

   Image1 -> Width = 600;
   Image1 -> Height = 350;
   Image1 -> Position -> X = 0;
   Image1 -> Position -> Y = 0;

   Image2 -> Width = 600;
   Image2 -> Height = 350;
   Image2 -> Position -> X = 0;
   Image2 -> Position -> Y = 0;

   Label1 -> Position -> X = 230;
   Label1 -> Position -> Y = -10;
   Label1 -> Size -> Width = 380;
   Label1 -> Size -> Height = 375;
   Label1 -> TextSettings -> Font -> Size = 14;
   Label1 -> TextSettings -> FontColor = claBlack;
   Label1 -> Size -> PlatformDefault = False;
   Label1 -> Font -> Style = TFontStyles ( ) << fsBold;

   RoundRect1 -> Width = 85;
   RoundRect1 -> Height = 25;
   RoundRect1 -> Position -> X = 290;
   RoundRect1 -> Position -> Y = 67;

   RoundRect2 -> Width = 85;
   RoundRect2 -> Height = 25;
   RoundRect2 -> Position -> X = 290;
   RoundRect2 -> Position -> Y = 67;
   RoundRect2 -> OnClick = FormShow;

   RoundRect3 -> Width = 119;
   RoundRect3 -> Height = 25;
   RoundRect3 -> Position -> X = 206;
   RoundRect3 -> Position -> Y = 270;

   RoundRect4 -> Width = 119;
   RoundRect4 -> Height = 25;
   RoundRect4 -> Position -> X = 206;
   RoundRect4 -> Position -> Y = 270;
}
//---------------------------------------------------------------------------
int verificaTabuada ( int n ) {
int i, b;
for ( i = 1; i <= 10; i++ ) {
b = n * i;
Form1 -> Label1 -> Text = Form1 -> Label1 -> Text + StrToInt ( n );
Form1 -> Label1 -> Text = Form1 -> Label1 -> Text + " X ";
Form1 -> Label1 -> Text = Form1 -> Label1 -> Text + StrToInt ( i );
Form1 -> Label1 -> Text = Form1 -> Label1 -> Text + " = ";
Form1 -> Label1 -> Text = Form1 -> Label1 -> Text + StrToInt ( b );
Form1 -> Label1 -> Text = Form1 -> Label1 -> Text + "\n";
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormShow ( TObject *Sender ) {
   Label_Manual ( Sender );
   Image2 -> Visible = false;
   Image1 -> Visible = true;

   RoundRect1 -> Visible = true;
       RoundRect2 -> Visible = false;
   RoundRect3 -> Visible = false;
   RoundRect4 -> Visible = false;
   int n;
   String str_1;
   x++;
   if ( x == 2 ) {
   n = StrToInt ( Edit1 -> Text );
   if ( n < 20 && n > 0 ) {
verificaTabuada ( n );
Image2 -> Visible = true;
RoundRect3 -> Visible = true;
RoundRect1 -> Visible = false;
RoundRect2 -> Visible = false;

   }
   else {
   Edit1 -> Text = " ";
  x = 0;
   }
   x = 0;
}

}
//---------------------------------------------------------------------------
void __fastcall TForm1::RoundRect1MouseEnter ( TObject *Sender ) {
RoundRect1 -> Visible = false;
RoundRect2 -> Visible = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RoundRect2MouseLeave ( TObject *Sender ) {
   if ( x == 1 ) {
RoundRect2 -> Visible = false;
RoundRect1 -> Visible = true;
   }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RoundRect3MouseEnter ( TObject *Sender ) {
RoundRect3 -> Visible = false;
RoundRect4 -> Visible = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RoundRect4MouseLeave ( TObject *Sender ) {
if ( x == 0 ) {
RoundRect4 -> Visible = false;
RoundRect3 -> Visible = true;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RoundRect4Click ( TObject *Sender ) {
FormShow ( Sender );
Edit1 -> SetFocus ( );
Edit1 -> Text = " ";
Label1 -> Text = " ";
}
//---------------------------------------------------------------------------


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

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <FMX.Controls.hpp>
#include <FMX.Forms.hpp>
#include <FMX.Controls.Presentation.hpp>
#include <FMX.Edit.hpp>
#include <FMX.StdCtrls.hpp>
#include <FMX.Types.hpp>
#include <FMX.Objects.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TEdit *Edit1;
TLabel *Label1;
TImage *Image1;
TImage *Image2;
TRoundRect *RoundRect1;
TRoundRect *RoundRect2;
TRoundRect *RoundRect3;
TRoundRect *RoundRect4;
void __fastcall FormShow ( TObject *Sender );
void __fastcall Label_Manual ( TObject *Sender );
void __fastcall RoundRect1MouseEnter(TObject *Sender);
void __fastcall RoundRect2MouseLeave(TObject *Sender);
void __fastcall RoundRect3MouseEnter(TObject *Sender);
void __fastcall RoundRect4MouseLeave(TObject *Sender);
void __fastcall RoundRect4Click(TObject *Sender);

private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

Nenhum comentário:

Postar um comentário

Observação: somente um membro deste blog pode postar um comentário.