terça-feira, 2 de fevereiro de 2021

C++ builder - botão para click único

 


Estamos mostrando neste exemplo um botão
para click único, que poderia ter sido feito
somente configurando nas propriedades 
do objeto TButton do C++ builder,
mas somos rebeldes mesmo então resolvemos
criar tudo na mão, nada foi inserido no form,
e os eventos também foram criados utilizando
apenas códigos, no final, ficou tudo perfeito.
Assista este pequeno vídeo do programa funcionando:




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

#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 w;
   TText *Text1;
   TImage *Image1;
   TImage *Image2;
   TImage *Image3;
   TImage *Image4;
TCircle *Circle1;
//---------------------------------------------------------------------------
void __fastcall TForm1::Label_Manual ( TObject *Sender ) {
Rectangle1 -> Width = 600;
Rectangle1 -> Height = 300;
Rectangle1 -> Position -> X = 0;
Rectangle1 -> Position -> Y = 0;
//Rectangle1 -> Fill -> Color = ( RGB ( 255, 0, 205 ) );
Rectangle1 -> Size -> PlatformDefault = False;
Rectangle1 -> Stroke -> Color = claYellow;
//Rectangle1 -> Stroke -> Kind = TBrushKind::Solid;
//Rectangle1 -> Stroke -> Color = ( RGB ( 255, 255, 0 ) );
Rectangle1 -> Stroke -> Thickness = 10;
Rectangle1 -> XRadius = 15;
Rectangle1 -> YRadius = 15;

Label1 -> Position -> X = 220;
Label1 -> Position -> Y = 100;
Label1 -> Size -> Width = 500;
Label1 -> Size -> Height = 19;
//Label4 -> AutoSize = True;
Label1 -> TextSettings -> Font -> Family = "Garamound";
Label1 -> TextSettings -> Font -> Size = 18;
Label1 -> TextSettings -> FontColor = claRed;
Label1 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
//Label1 -> Text = "FMX - PROCESSMESSAGES";

Text1  = new TText ( this );
Text1 -> Parent = Form1;
//Text1 -> AutoSize = True;
Text1 -> TextSettings -> Font -> Family = "Garamound";
Text1 -> TextSettings -> Font -> Size = 20;
Text1 -> TextSettings -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
//Text1-> Color = clYellow;
Text1 -> TextSettings -> FontColor = claRed;
Text1 -> Width = 500;
Text1 -> Height = 19;
Text1 -> Position -> Y = 15;
Text1 -> Position -> X = 60;
Text1 -> Text = "FMX - BOTÃO PARA UM ÚNICO ESTADO";

  Image3 = new TImage ( this );
  Image3 -> Bitmap -> LoadFromFile ("Bal_green.bmp");
  Image3 -> Parent = Form1;
  Image3 -> Height = 50;
  Image3 -> Width = 50;
  Image3 -> Position -> X = 60;
  Image3 -> Position -> Y = 230;
  Image3 -> OnClick = Image3Click;

  Image4 = new TImage ( this );
  Image4 -> Bitmap -> LoadFromFile ("Bal_blue_claro.bmp");
  Image4 -> Parent = Form1;
  Image4 -> Height = 50;
  Image4 -> Width = 50;
  Image4 -> Position -> X = 480;
  Image4 -> Position -> Y = 230;
  Image4 -> OnClick = Image4Click;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate ( TObject *Sender ) {
   Label_Manual ( Sender );
  Image1 = new TImage ( this );
  Image1 -> Bitmap -> LoadFromFile ("smiling-face_1.bmp");
  Image1 -> Parent = Form1;
  Image1 -> Height = 50;
  Image1 -> Width = 30;
  Image1 -> Position -> X = 198;
  Image1 -> Position -> Y = 130;
}
//---------------------------------------------------------------------------
int val_ue;
int mouse_Clicked ( ) {
if ( val_ue == 1 ) {
val_ue = 0;
} else {
val_ue = 1;
}
return val_ue;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image3Click(TObject *Sender) {
  Image3 = new TImage ( this );
  Image3 -> Bitmap -> LoadFromFile ("Bal_green_claro.bmp");
  Image3 -> Parent = Form1;
  Image3 -> Height = 50;
  Image3 -> Width = 50;
  Image3 -> Position -> X = 60;
  Image3 -> Position -> Y = 230;
  if ( mouse_Clicked ( ) == 1 ) {
Beep ( 500, 500 );
  Image1 = new TImage ( this );
  Image1 -> Bitmap -> LoadFromFile ("smiling-face_2.bmp");
  Image1 -> Parent = Form1;
  Image1 -> Height = 50;
  Image1 -> Width = 30;
  Image1 -> Position -> X = 198;
  Image1 -> Position -> Y = 130;

  Image2 = new TImage ( this );
  Image2 -> Bitmap -> LoadFromFile ("Por_5.bmp");
  Image2 -> Parent = Form1;
  Image2 -> Height = 60;
  Image2 -> Width = 210;
  Image2 -> Position -> X = 198;
  Image2 -> Position -> Y = 230;
  }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image4Click(TObject *Sender) {
  Close ( );
}
//---------------------------------------------------------------------------

Nenhum comentário:

Postar um comentário

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