Einzelnen Beitrag anzeigen

madas

Registriert seit: 9. Aug 2007
207 Beiträge
 
#4

AW: Mehrzeiliger Header im VST

  Alt 20. Jun 2011, 14:31
Keiner eine Idee?
Statt des VST den DrawTree nehmen und den Text selber malen.

Dazu im OnHeaderDrawQueryElements folgendes machen:

Include(Elements, hpeText); und im OnAdvancedHeaderDraw darauf reagieren.

Hier mal ein Beispiel (musst Du für Deine Zwecke anpassen):

Delphi-Quellcode:
procedure TForm.AdvancedHeaderDraw(Sender: TVTHeader; var PaintInfo: THeaderPaintInfo;
  const Elements: THeaderPaintElements);
var
  rNormalText, rResultText, rBemerkung, rTypWachstum: TRect;
  x, y: Integer;
  Text: WideString;
  Size: TSize;
begin
  inherited;
  if (hpeText in Elements) then
  begin
    // Trennlinien zeichnen
    if (PaintInfo.Column.Index >= abDieserSpalte) then
    begin
      rNormalText := PaintInfo.PaintRectangle;
      InflateRect(rNormalText, 0, -1);
      OffsetRect(rNormalText, -1, -1);
      if (PaintInfo.IsDownIndex) then
        OffsetRect(rNormalText, 1, 1);
      PaintInfo.TargetCanvas.Pen.Color := clInactiveBorder;
      PaintInfo.TargetCanvas.Pen.Width := 1;
      // Trennlinie Ansatz und typ. Wachstum
      y := rNormalText.Top;
      y := y + ((rNormalText.Bottom - rNormalText.Top) div 3);
      PaintInfo.TargetCanvas.MoveTo(rNormalText.Left, y);
      PaintInfo.TargetCanvas.LineTo(rNormalText.Right, y);
      // Trennlinie typ. Wachstum und Rest
      y := rNormalText.Top;
      y := y + (((rNormalText.Bottom - rNormalText.Top) div 3) * 2) + (FrameVSTTestItemList.Tree.TextMargin div 2);
      PaintInfo.TargetCanvas.MoveTo(rNormalText.Left, y);
      PaintInfo.TargetCanvas.LineTo(rNormalText.Right, y);
      x := rNormalText.Left + leftPartWidth;
      PaintInfo.TargetCanvas.MoveTo(x, y);
      PaintInfo.TargetCanvas.LineTo(x, rNormalText.Bottom);
    end;

    // Bereiche berechnen
    rNormalText := PaintInfo.PaintRectangle;
    InflateRect(rNormalText, -PaintInfo.Column.Margin, 0);
    if (PaintInfo.IsDownIndex) then
      OffsetRect(rNormalText, 1, 1);

    // Normalen Text bestimmen und berechnen
    Text := PaintInfo.Column.Text;
    GetTextExtentPoint32W(PaintInfo.TargetCanvas.Handle, PWideChar(Text), Length(Text), Size);
    if (PaintInfo.Column.Index > -1) and (Size.cx > (rNormalText.Right - rNormalText.Left)) then
      Text := ShortenString(PaintInfo.TargetCanvas.Handle, Text, (rNormalText.Right - rNormalText.Left), 0);

    SetBkMode(PaintInfo.TargetCanvas.Handle, TRANSPARENT);
    SetTextColor(PaintInfo.TargetCanvas.Handle, ColorToRGB(clWindowText));

    if (PaintInfo.Column.Index >= abDieserSpalte) then
    begin
      Windows.DrawTextW(PaintInfo.TargetCanvas.Handle, PWideChar(Text),
        Length(Text), rNormalText, DT_LEFT or DT_TOP or DT_NOPREFIX or DT_SINGLELINE);
      OffsetRect(rNormalText, 0, -2);

      // typ. Wachstum zeichnen
      rTypWachstum := rNormalText;
      Text := 'typ. Wachstum';
      GetTextExtentPoint32W(PaintInfo.TargetCanvas.Handle, PWideChar(Text), Length(Text), Size);
      if (PaintInfo.Column.Index > -1) and (Size.cx > (rTypWachstum.Right - rTypWachstum.Left)) then
        Text := ShortenString(PaintInfo.TargetCanvas.Handle, Text, (rTypWachstum.Right - rTypWachstum.Left), 0);
      Windows.DrawTextW(PaintInfo.TargetCanvas.Handle, PWideChar(Text),
        Length(Text), rTypWachstum, DT_LEFT or DT_VCENTER or DT_NOPREFIX or DT_SINGLELINE);

      // unteren Bereich zeichnen
      rResultText := rNormalText;
      //rResultText.Right := rResultText.Left + ((rResultText.Right-rResultText.Left) div 2) - PaintInfo.Column.Margin;
      rResultText.Right := rResultText.Left + leftPartWidth - PaintInfo.Column.Margin;
      Text := 'Kultur';
      GetTextExtentPoint32W(PaintInfo.TargetCanvas.Handle, PWideChar(Text), Length(Text), Size);
      if (PaintInfo.Column.Index > -1) and (Size.cx > (rResultText.Right - rResultText.Left)) then
        Text := ShortenString(PaintInfo.TargetCanvas.Handle, Text, (rResultText.Right - rResultText.Left), 0);
      Windows.DrawTextW(PaintInfo.TargetCanvas.Handle, PWideChar(Text),
        Length(Text), rResultText, DT_LEFT or DT_BOTTOM or DT_NOPREFIX or DT_SINGLELINE);

      rBemerkung := rNormalText;
      //rBemerkung.Left := rBemerkung.Left + ((rBemerkung.Right-rBemerkung.Left) div 2) + PaintInfo.Column.Margin;
      rBemerkung.Left := rBemerkung.Left + leftPartWidth + PaintInfo.Column.Margin;
      Text := 'Bemerkung';
      GetTextExtentPoint32W(PaintInfo.TargetCanvas.Handle, PWideChar(Text), Length(Text), Size);
      if (PaintInfo.Column.Index > -1) and (Size.cx > (rBemerkung.Right - rBemerkung.Left)) then
        Text := ShortenString(PaintInfo.TargetCanvas.Handle, Text, (rBemerkung.Right - rBemerkung.Left), 0);
      Windows.DrawTextW(PaintInfo.TargetCanvas.Handle, PWideChar(Text),
        Length(Text), rBemerkung, DT_LEFT or DT_BOTTOM or DT_NOPREFIX or DT_SINGLELINE);
    end else
    begin
      // Normalen Text ausgeben
      Windows.DrawTextW(PaintInfo.TargetCanvas.Handle, PWideChar(Text),
        Length(Text), rNormalText, DT_LEFT or DT_VCENTER or DT_NOPREFIX or DT_SINGLELINE);
    end;
  end;
end;
So oder so ähnlich sollte es klappen.
  Mit Zitat antworten Zitat