terça-feira, 8 de setembro de 2020

C++ builder - capturando coordenadas do form

Aqui está um exemplo de como capturar
as coordenadas do form pelo click do mouse.
Aqui está um exemplo de como capturar
as coordenadas do form pelo movimento do mouse.
Neste aqui estamos utilisando o evento FormMouseMove,
no exemplo anterior, utilizamos o evento FormMouseDown.


Veja abaixo os códigos do programa

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

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
 //---------------------------------------------------------------------------
void __fastcall TForm1::Informe ( TObject *Sender ) {
Canvas -> Font-> Style = TFontStyles ( ) << fsItalic;
        Canvas -> Font -> Size = 11;
        Canvas -> Font -> Name = "Arial";
        Canvas -> Font -> Color = clBlack;
Canvas -> TextOut ( 160, 250, "Por: " );
Canvas -> Font -> Color = clRed;
Canvas -> TextOut ( 200, 250, "Samuel Lima" );
Canvas -> Font -> Color = clBlue;
Canvas -> TextOut ( 160, 265, "sa_sp10@hotmail.com" );
}
 //---------------------------------------------------------------------------
void __fastcall TForm1::Label_Manual ( TObject *Sender ) {
Label1 -> Visible = true;
Label1 -> Font -> Size = 14;
Label1 -> Font -> Name = "alarm clock";
Label1 -> Font-> Style = TFontStyles ( ) << fsBold;
Label1 -> Font -> Color = clRed;
Label1 -> Width = 100;
Label1 -> Height = 70;
Label1 -> Left = 20;
Label1 -> Top = 50;

BitBtn1 -> Font -> Name = "Arial";
        BitBtn1 -> Visible = true;
        BitBtn1 -> Font -> Size = 12;
BitBtn1 -> Font-> Style = TFontStyles ( ) << fsItalic << fsBold;
        BitBtn1 -> Font -> Color = clBlack;
BitBtn1 -> Width = 50;
BitBtn1 -> Height = 22;
BitBtn1 -> Top = 260;
BitBtn1 -> Left = 520;
BitBtn1 -> Caption = ( "Sair" );
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormMouseDown ( TObject *Sender, TMouseButton Button, TShiftState Shift,
  int X, int Y ) {
Label1 -> Caption = StrToInt ( X );
Label1 -> Caption = Label1 -> Caption + "\n";
Label1 -> Caption = Label1 -> Caption + StrToInt ( Y );
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormShow ( TObject *Sender ) {
Label_Manual ( Sender );
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormPaint ( TObject *Sender ) {
//Alterando a cor do form
Canvas -> Brush -> Color = static_cast < TColor > ( RGB ( 255, 255, 205 ) );
//Adiciona um fundo nos textos do canvas com RGB
SetBkColor ( Canvas -> Handle, RGB ( 205, 255, 051 ) );
Canvas -> Font -> Size = 14;
Canvas -> Font-> Style = TFontStyles ( ) << fsItalic;
Canvas -> Font -> Name = "Arial";
                 Canvas -> Pen -> Width = 10;
Canvas -> Pen -> Color = clBlue;
Canvas -> RoundRect ( 05, 05, 595, 295, 25, 25 );
//Colorindo a cor de frente do canvas com RGB
SetTextColor ( Canvas -> Handle, RGB ( 0, 0, 0 ) );
Canvas -> TextOut ( 30, 15, "C++ BUILDER - CAPTURANDO COORDENADAS DO FORM" );
Informe ( Sender );
   }
   //---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn1Click ( TObject *Sender ) {
Close ( );
}
//------------------------------------------------------------------------------

Nenhum comentário:

Postar um comentário

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