Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Algorithmen, Datenstrukturen und Klassendesign (https://www.delphipraxis.net/78-algorithmen-datenstrukturen-und-klassendesign/)
-   -   Delphi Zeichnen in Paintbox erst nach Refresh (https://www.delphipraxis.net/182009-zeichnen-paintbox-erst-nach-refresh.html)

Captnemo 24. Sep 2014 11:41

Zeichnen in Paintbox erst nach Refresh
 
Hi,

ich bastel grad an einer Urlaubplanerkomponente.
Die Komponente setze ich aus Panels zusammen, damit ich feststehende Zeilen und Spalten, und einen scrollbaren Anzeigebereich habe.
Jetzt will ich in einer Paintbox, die ich mir auf ein Panel gesetzt habe die Datumscala zeichnen, aber das will nicht so richtig funktionieren. Im Grunde zeichnet er erst, wenn ich die Komponente in eine Form setze, diese starte und ein Refresh auf meinem Basispanel durchführe.

Hier mal mein Create der Komponente und die Function in der ich zeichnen will:

Delphi-Quellcode:
constructor TUrlaubsplaner.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  self.FPersons:=TPersons.Create(TPerson);
  self.FEntryTypes:=TEntryTypes.Create(TEntryType);
  self.FEntries:=TEntries.Create(TEntry);
  self.FColors:=TColors.Create;
  self.FColors.BackColor:=clWhite;
  self.FColors.DayColorMo:=clGradientActiveCaption;
  self.FColors.DayColorDi:=clGradientInactiveCaption;
  self.FColors.DayColorMi:=clGradientActiveCaption;
  self.FColors.DayColorDo:=clGradientInactiveCaption;
  self.FColors.DayColorFr:=clGradientActiveCaption;
  self.FColors.DayColorSa:=clHighlight;
  self.FColors.DayColorSo:=clHotLight;
  self.FColors.PersonColor1:=clCream;
  self.FColors.PersonColor2:=clMoneyGreen;
  self.FColors.GridLineColor:=clBlack;
  self.FColors.PersonGridColor:=clBlack;
  self.FColors.DayGridColor:=clBlack;
  self.FColors.Color:=clCream;
  self.FShowMonths:=True;
  self.FColumnDayWidth:=20;
  self.FStartDay:=Now;
  self.FEndDay:=now+10;

  FPanelLeft:= TPanel.Create(Self); //alLeft
  FPanelLeft.Parent:=Self;
  FPanelLeft.Align:=alLeft;
  FPanelLeft.Width:=80;
  FPanelLeft.BevelOuter:=bvNone;

  FPanelLeftBottom:=TPanel.Create(Self); //alBottom
  FPanelLeftBottom.Parent:=FPanelLeft;
  FPanelLeftBottom.Align:=alBottom;
  FPanelLeftBottom.Height:=17;
  FPanelLeftBottom.BevelOuter:=bvNone;
  FPanelLeftBottom.Color:=self.FColors.Color;

  FPanelLeftTop:=TPanel.Create(Self);    //alTop
  FPanelLeftTop.Parent:=FPanelLeft;
  FPanelLeftTop.Align:=alTop;
  FPanelLeftTop.Height:=40;
  FPanelLeftTop.BevelOuter:=bvNone;
  FPanelLeftTop.Color:=self.FColors.Color;

  FPanelPersonal:=TPanel.Create(Self);  //alClient
  FPanelPersonal.Parent:=FPanelLeft;
  FPanelPersonal.Align:=alClient;
  FPanelPersonal.BevelOuter:=bvNone;

  FSplitter:=TSplitter.Create(self);
  FSplitter.Parent:=Self;
  FSplitter.Left:=185;
  FSplitter.Align:=alLeft;
  FSplitter.Color:=clSilver;

  FPanelRight:=TPanel.Create(Self);     //alClient
  FPanelRight.Parent:=self;
  FPanelRight.Align:=alClient;
  FPanelRight.BevelOuter:=bvNone;

  FPanelRightBottom:=TPanel.Create(Self); //alBottom
  FPanelRightBottom.Parent:=FPanelRight;
  FPanelRightBottom.Align:=alBottom;
  FPanelRightBottom.Height:=17;
  FPanelRightBottom.BevelOuter:=bvNone;

  FPanelRightBottomRight:=TPanel.Create(self); //alRight
  FPanelRightBottomRight.Parent:=FPanelRightBottom;
  FPanelRightBottomRight.Align:=alRight;
  FPanelRightBottomRight.Width:=17;
  FPanelRightBottomRight.BevelOuter:=bvNone;
  FPanelRightBottomRight.Color:=self.FColors.Color;

  FScrollbarHorizontal:=TScrollbar.Create(Self); //alRight
  FScrollbarHorizontal.Parent:=FPanelRightBottom;
  FScrollbarHorizontal.Kind:=sbHorizontal;
  FScrollbarHorizontal.Align:=alClient;

  FPanelRightTop:=TPanel.Create(Self); //alTop
  FPanelRightTop.Parent:=FPanelRight;
  FPanelRightTop.Align:=alTop;
  FPanelRightTop.Height:=40;
  FPanelRightTop.BevelOuter:=bvNone;

  FPanelRightTopRight:=TPanel.Create(Self); //alRight
  FPanelRightTopRight.Parent:=FPanelRightTop;
  FPanelRightTopRight.Align:=alRight;
  FPanelRightTopRight.Width:=17;
  FPanelRightTopRight.BevelOuter:=bvNone;
  FPanelRightTopRight.Color:=self.FColors.Color;

  FPanelDate:=TPanel.Create(Self); //alClient
  FPanelDate.Parent:=FPanelRightTop;
  FPanelDate.Align:=alClient;
  FPanelDate.BevelOuter:=bvNone;

  FPanelDays:=TPanel.Create(Self); //alClient
  FPanelDays.Parent:=FPanelRight;
  FPanelDays.Align:=alClient;
  FPanelDays.BevelOuter:=bvNone;

  FScrollbarVertical:=TScrollBar.Create(Self); //alClient
  FScrollbarVertical.Parent:=FPanelDays;
  FScrollbarVertical.Kind:=sbVertical;
  FScrollbarVertical.Align:=alRight;

  FDatePaint:=TPaintBox.Create(self);
  FDatePaint.Parent:=FPanelDate;
  FDatePaint.Left:=0;
  FDatePaint.Top:=0;
  FDatePaint.Height:=FPanelDate.Height;

  GenerateDatePanelView;
  self.Refresh; //hat nichts verändert.
end;

procedure TUrlaubsplaner.GenerateDatePanelView;
var
  NumOfDays: Integer;
  RectMonth: TRect;
  r: TRect;
  AktMonth: Integer;
  DayName: string;
  I: Integer;
begin
  NumOfDays:=DaysBetween(self.FStartDay, self.FEndDay);
  FDatePaint.Width:=NumOfDays*Self.FColumnDayWidth;
  RectMonth.Left:=FDatePaint.Left;
  RectMonth.Top:=FDatePaint.Top;
  RectMonth.Height:=20;
  for I := 0 to NumOfDays do
  begin
    r.Left:=FDatePaint.Left+(i*FColumnDayWidth);
    if FShowMonths then
      r.Top:=FDatePaint.Top+RectMonth.Height+1 else
      r.Top:=FDatePaint.Top;
    r.Height:=20;
    r.Width:=FColumnDayWidth;
    case DayOfWeek(FStartDay+i) of
      1: FDatePaint.Canvas.Brush.Color:=self.FColors.DayColorSo;
      2: FDatePaint.Canvas.Brush.Color:=self.FColors.DayColorMo;
      3: FDatePaint.Canvas.Brush.Color:=self.FColors.DayColorDi;
      4: FDatePaint.Canvas.Brush.Color:=self.FColors.DayColorMi;
      5: FDatePaint.Canvas.Brush.Color:=self.FColors.DayColorDo;
      6: FDatePaint.Canvas.Brush.Color:=self.FColors.DayColorFr;
      7: FDatePaint.Canvas.Brush.Color:=self.FColors.DayColorSa;
    end;
    case DayOfWeek(FStartDay+i) of
      1: DayName:='So';
      2: DayName:='Mo';
      3: DayName:='Di';
      4: DayName:='Mi';
      5: DayName:='Do';
      6: DayName:='Fr';
      7: DayName:='Sa';
    end;
    FDatePaint.Canvas.Pen.Color:=self.FColors.DayGridColor;
    FDatePaint.Canvas.FillRect(r);
    FDatePaint.Canvas.MoveTo(r.Right-1, r.Top);
    FDatePaint.Canvas.LineTo(r.Right-1, r.Bottom);
    FDatePaint.Canvas.TextRect(r, 2, 2, IntToStr(DayOf(FStartDay+i)));
    FDatePaint.Canvas.TextRect(r, 12, 2, DayName);
  end;
end;
Die fest eingetragenen Werte sind erstmal nur zum Testen, sind hier zu vernachlässigen.

Bitte nicht gleich steinigen, weil ich es so gemacht, wie ich es gemacht habe. Ist halt learning by doing.

himitsu 24. Sep 2014 11:46

AW: Zeichnen in Paintbox erst nach Refresh
 
Nein, man zeichnet im Paint/Refresh.

Wozu hat das Ding sonst ein OnPaint-Ereignis?


Im Paint wird immer alles neu gezeichnet (oder der entsprechende Teil ... falls die PaintBox das Clipping auslesen lässt).

* entweder direkt zeichnen (wenn es schnell gehn muß) und im OnPaint der Reparatur/Neuzeichnen-Code
* oder PaintBox.Repaint aufrufen und immer nur im OnPaint zeichnen

Captnemo 24. Sep 2014 12:05

AW: Zeichnen in Paintbox erst nach Refresh
 
Jaaaaaa, verdamte Axt :lol:

Mann, ich wird alt....zu alt.


Alle Zeitangaben in WEZ +1. Es ist jetzt 09:41 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz