AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Programmieren allgemein Rechteck in stringgrid teilen und einfärben
Thema durchsuchen
Ansicht
Themen-Optionen

Rechteck in stringgrid teilen und einfärben

Ein Thema von Hartfrid Krause · begonnen am 22. Nov 2011 · letzter Beitrag vom 24. Nov 2011
 
shmia

Registriert seit: 2. Mär 2004
5.508 Beiträge
 
Delphi 5 Professional
 
#3

AW: Rechteck in stringgrid teilen und einfärben

  Alt 22. Nov 2011, 17:17
Ich werfe mal meine Prozedure DrawBiColorRect in die Runde.
Damit wird gezeigt, wie man das Problem unabhängig vom StringGrid und Formular verallgemeinert
und wiederverwendbar lösen kann.
Eine saubere Sache, denn es wird der Canvas und das Zielrechteck übergeben
und ob dahinter ein Stringgrid, DBGrid, Image oder was auch immer steht spielt keine Rolle mehr.

Danach sollte die Eigenentwicklung einer Prozedure die 3 Farben benützt kein Problem mehr sein.

Delphi-Quellcode:
// Zeichnet ein zweifarbiges Recheck auf einen Canvas
// mode:
// horizontal geteilt -
// vertikal geteilt |
// diagonal geteilt /
// diagonal geteilt \
procedure DrawBiColorRect(canvas:TCanvas; r:TRect; c1, c2:TColor; mode:char);
var
   rect1, rect2 : TRect;
   poly1, poly2 : array[0..2] of TPoint;

   procedure DrawRects;
   begin
      canvas.Brush.Color := c1;
      canvas.FillRect(rect1);
      canvas.Brush.Color := c2;
      canvas.FillRect(rect2);
   end;

   procedure DrawPoly;
   begin
      canvas.Brush.Color := c1;
      canvas.Pen.Color := c1;
      canvas.Polygon(poly1);
      canvas.Brush.Color := c2;
      canvas.Pen.Color := c2;
      canvas.Polygon(poly2);
   end;
begin
   case mode of
      '|':
      begin
         rect1 := r;
         rect2 := r;
         rect1.Right := ((rect1.Right-rect1.Left) div 2) + rect1.Left;
         rect2.Left := rect1.Right;
         DrawRects;
      end;

      '-':
      begin
         rect1 := r;
         rect2 := r;
         rect1.Bottom := ((rect1.Bottom-rect1.Top) div 2) + rect1.Top;
         rect2.Top := rect1.Bottom;
         DrawRects;
      end;

      '/':
      begin
         poly1[0] := r.TopLeft;
         poly1[1] := Point(r.Right, r.Top);
         poly1[2] := Point(r.Left, r.Bottom);
         poly2[0] := r.BottomRight;
         poly2[1] := Point(r.Right, r.Top);
         poly2[2] := Point(r.Left, r.Bottom);
         DrawPoly;
      end;

      '\':
      begin
         poly1[0] := r.TopLeft;
         poly1[1] := Point(r.Right, r.Top);
         poly1[2] := Point(r.Right, r.Bottom);
         poly2[0] := r.BottomRight;
         poly2[1] := Point(r.Left, r.Top);
         poly2[2] := Point(r.Left, r.Bottom);
         DrawPoly;
      end;
   end;
end;
Andreas

Geändert von shmia (22. Nov 2011 um 17:19 Uhr)
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 11:33 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