helldanger1
GForum VIP
- Entrou
- Ago 1, 2007
- Mensagens
- 29,631
- Gostos Recebidos
- 1
Os componentes Button são baseados em Standard Windows Button Control. Nas primeiras versões do Windows, uma aplicação pode alterar o background de um button pelo tratamento da mensagem WM_CTLCOLORBTN. Entretanto, a partir do Windows 95/NT 4.0 ou superior, mudanças nessa mensagem não afetam os Buttons.
A solução seria criar ou usar algum componente que aceita tal efeito.
O código abaixo simula um Button colorido através de um Panel colocado no Form:
//---------------------------------------------------------------------------
#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::FormCreate(TObject *Sender)
{
Panel1->Caption = "";
Panel1->Color = clYellow;
Panel1->BevelWidth = 2;
}
//---------------------------------------------------------------------------
void __fastcall TForm1:
anel1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
Panel1->BorderStyle = bsSingle;
Panel1->BevelWidth = 0;
}
//---------------------------------------------------------------------------
void __fastcall TForm1:
anel1MouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
Panel1->BorderStyle = bsNone;
Panel1->BevelWidth = 2;
Form1->Color = clFuchsia;
ShowMessage("Panel ou Button?");
}
//---------------------------------------------------------------------------
NOTA: Por questões visuais, nesses casos, prefira usar o evento OnMouseDown ao evento OnClick do Panel.
A solução seria criar ou usar algum componente que aceita tal efeito.
O código abaixo simula um Button colorido através de um Panel colocado no Form:
//---------------------------------------------------------------------------
#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::FormCreate(TObject *Sender)
{
Panel1->Caption = "";
Panel1->Color = clYellow;
Panel1->BevelWidth = 2;
}
//---------------------------------------------------------------------------
void __fastcall TForm1:
TMouseButton Button, TShiftState Shift, int X, int Y)
{
Panel1->BorderStyle = bsSingle;
Panel1->BevelWidth = 0;
}
//---------------------------------------------------------------------------
void __fastcall TForm1:
TShiftState Shift, int X, int Y)
{
Panel1->BorderStyle = bsNone;
Panel1->BevelWidth = 2;
Form1->Color = clFuchsia;
ShowMessage("Panel ou Button?");
}
//---------------------------------------------------------------------------
NOTA: Por questões visuais, nesses casos, prefira usar o evento OnMouseDown ao evento OnClick do Panel.