procedure TmyPanel.Paint;
var
myRect,TextRect,CalcRect,R : TRect;
myBorderWidth,myBorderWidthRightBottom:Integer;
myAlignment : Cardinal;
Region: hrgn;
begin
myRect := GetClientRect;
Canvas.FillRect(myRect);
Canvas.Brush.Style := bsSolid;
Canvas.Brush.Color := FBgColorFrom;
Canvas.Pen.Mode := pmCopy;
Canvas.Pen.Style := BorderStyle;
Canvas.Pen.Width := BorderWidth;
Canvas.Pen.Color := BorderColor;
self.Canvas.Font.Assign(Font);
//zeichnen des gradients
if PaintGradient
then
DrawGradient(Canvas, BgColorFrom, BgColorTo, myRect, GradientDirection);
//zeichnen des bildes, wenn vorhanden
if Picture <>
nil then
if PictureStretched
then
Canvas.StretchDraw(myRect,Picture.Graphic)
else
Canvas.Draw(0,0,Picture.Graphic);
//berechnen und zeichnen des rahmens
if BorderWidth > 0
then
begin
case BorderWidth
of
1 :
begin
myBorderWidth := 0;
myBorderWidthRightBottom := 1;
end;
else begin
myBorderWidth := BorderWidth
div 2;
myBorderWidthRightBottom := BorderWidth
div 2;
end;
end;
Canvas.MoveTo(0 + myBorderWidth,0);
Canvas.LineTo(myRect.Left + myBorderWidth,myRect.Bottom);
Canvas.MoveTo(0,0 + myBorderWidth);
Canvas.LineTo(myRect.Right,myRect.Top + myBorderWidth);
Canvas.MoveTo(self.Width-myBorderWidthRightBottom,0);
Canvas.LineTo(myRect.Right-myBorderWidthRightBottom,myRect.Bottom);
Canvas.MoveTo(0,self.Height-myBorderWidthRightBottom);
Canvas.LineTo(myRect.Right,myRect.Bottom-myBorderWidthRightBottom);
end;
//schreiben des textes
TextRect := Rect(BorderWidth + TextMargin, BorderWidth + TextMargin, self.Width-BorderWidth - TextMargin, self.Height-BorderWidth - TextMargin);
SetBkMode(Canvas.Handle, TRANSPARENT);
//init
myAlignment := 0;
case TextAlign
of
taCenter : myAlignment := DT_CENTER;
taLeftJustify : myAlignment := DT_LEFT;
taRightJustify : myAlignment := DT_RIGHT;
end;
IF FTextWordwrap
then myAlignment := MyAlignment
or DT_WORDBREAK
else myAlignment := MyAlignment
or DT_SINGLELINE;
if FLayout <> tlTop
then
begin
CalcRect := TextRect;
DrawText(Canvas.Handle, PChar(FText), -1, CalcRect, myAlignment
or DT_CALCRECT);
if FLayout = tlBottom
then OffsetRect(TextRect, 0, Height - CalcRect.Bottom)
else OffsetRect(TextRect, 0, (Height - CalcRect.Bottom)
div 2);
end;
DrawText(Canvas.Handle, PChar(FText), -1, TextRect, myAlignment);
// und jetzt machen wir den Rahmen unsichtbar
if CornerUse
and (CornerWidth > 0)
then begin
R := GetClientRect;
FullRgn := CreateRectRgn(0, 0, Width, Height);
CombineRgn( FullRgn, FullRgn, FullRgn, RGN_DIFF );
// alle sichtbaren Bereiche einblenden
Region := CreateRoundRectRgn(FBorderWidth, FBorderWidth, R.Right - FBorderWidth, R.Bottom - FBorderWidth, 20, 20);
CombineRgn( FullRgn, FullRgn, Region, RGN_OR );
DeleteObject(Region);
// alles Kombiniert und fertig
SetWindowRgn(
Handle, FullRgn, TRUE);
end else DoVisible;
end;