I am trying to create a new component from the TPaintBox. New component size is Rect(0,0,160,248). I drew two rectangles on newly component and I would like to implement events to each of above rectangle.
Get rectangle is located at Rect(102,43,157,63) and I would like to implement events like OnGetClick , OnGetMouseDown , OnGetMouseUp for this rectangle area .
Set rectangle is located at Rect(102,69,157,89) and I would like to implement events like OnSetClick, OnSetMouseDown, OnSetMouseUp for this rectangle area.
Rest of the new component area is going display values related to the VGauge and I am not included in below code.
class PACKAGE TVGauge : public TPaintBox
{
public:
virtual void __fastcall Paint(void) ;
};
void __fastcall TVGauge::Paint(void)
{
int ind1, ind2 ;
TRect tempR ;
String str;
Canvas->Font->Size = 8 ;
//whole rect
Canvas->Pen->Color = clSilver ;
Canvas->Brush->Color = clBtnFace ;
Canvas->Rectangle(ClientRect) ; //Rect(0,0,160,248)
//----------
Canvas->Pen->Color = clMedGray ;
Canvas->Font->Color = clWindowText ;
Canvas->Brush->Color = clWhite ;
//Get Button ; draw a rectangle and it should act like a button
Canvas->Rectangle(102 , 43 , 157 , 63 ) ;
Canvas->TextOut(112, 48 ,L"Get");
//Set Button ; draw a rectangle and it should act like a button
Canvas->Rectangle(102 , 69 , 157 , 89 ) ;
Canvas->TextOut(112, 74 ,L"Set");
//display values related to the VGauge
//..
//..
if(OnPaint != NULL) OnPaint(this) ;
}
I don't have any idea, how to implement above events for a new component. So, I am hoping to get suggestions to implement this component.
Override the virtual
MouseDown()andMouseUp()methods, eg:On a side note, you really should derive your component from
TGraphicControldirectly instead of fromTPaintBox. The only difference betweenTPaintBoxandTGraphicControlis thatTPaintBoxexposes anOnPaintevent, where it overridesPaint()to triggerOnPaint. You don't really need theOnPaintevent in your component at all, since you are doing all of your own painting (unless you really want users drawing over top of our painting).