procedure TmyPanel.Paint;
var
myRect,TextRect,CalcRect,R : TRect;
myBorderWidth,myBorderWidthRightBottom:Integer;
myAlignment : Cardinal;
Region: hrgn;
begin
if CornerUse
and (CornerWidth > 0)
then
begin
R := GetClientRect;
with Canvas
do
begin
Pen.Color := FBorderColor;
Region := CreateRoundRectRgn(0, 0, R.Right, R.Bottom, 20, 20);
FrameRgn(Canvas.Handle, Region, Canvas.Pen.Handle, R.Right, R.Bottom);
SetWindowRgn(
Handle, Region, True);
DeleteObject(Region);
Region := CreateRoundRectRgn(FBorderWidth, FBorderWidth, R.Right - FBorderWidth, R.Bottom - FBorderWidth, 20, 20);
FillRgn(Canvas.Handle, Region, Canvas.Brush.Handle);
SetWindowRgn(
Handle, Region, True);
DeleteObject(Region);
end;
DoVisible;
DoInvisible;
end;
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);
end;
Ich weiss, dass da noch ein wenig durcheinander ist und dass ich da durchaus Ordnung schaffen muss, aber ich hatte heute leider nur wenig zeit Zum Testen...Aber ich bring das auch bald
in Ordnung...