AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

DrawGradient und Windows 7 Basic Style

Ein Thema von pHL · begonnen am 17. Sep 2013 · letzter Beitrag vom 18. Sep 2013
 
pHL

Registriert seit: 27. Mai 2011
83 Beiträge
 
Delphi XE2 Professional
 
#1

DrawGradient und Windows 7 Basic Style

  Alt 17. Sep 2013, 12:44
Delphi-Version: XE

Hallo Leute!

Ich verwende folgende Funktion von Delphi-Treff um in einem TStringgrid einzelne Zellen mit einem Gradient zu zeichnen.

Delphi-Quellcode:
procedure TMainForm.DrawGradient(const Canvas: TCanvas; Color1, Color2: TColor;
                       ARect: TRect; GradientOrientation: TGradientOrientation);
var
  c1, c2, c: TPixelRec; //for easy access to RGB values as well as TColor value
  x, y: Integer; //current pixel position to be set
  OldPenWidth: Integer; //Save old settings to restore them properly
  OldPenStyle: TPenStyle;//see above
begin
  Canvas.Brush.Style := bsSolid;

  c1.Color := ColorToRGB(Color1); //convert system colors to RGB values
  c2.Color := ColorToRGB(Color2); //if neccessary
  OldPenWidth := Canvas.Pen.Width; //get old settings
  OldPenStyle := Canvas.Pen.Style;
  Canvas.Pen.Width:=1; //ensure correct pen settings
  Canvas.Pen.Style:=psInsideFrame;

  case GradientOrientation of
    goVertical:
    begin
      for y := 0 to ARect.Bottom - ARect.Top do
      begin
        c.r := Round(c1.r + (c2.r - c1.r) * y / (ARect.Bottom - ARect.Top));
        c.g := Round(c1.g + (c2.g - c1.g) * y / (ARect.Bottom - ARect.Top));
        c.b := Round(c1.b + (c2.b - c1.b) * y / (ARect.Bottom - ARect.Top));
        Canvas.Brush.Color := c.Color;
        Canvas.FillRect(Classes.Rect(ARect.Left, ARect.Top + y,
                                     ARect.Right, ARect.Top + y + 1));
      end;
    end;
    goHorizontal:
    begin
      for x := 0 to ARect.Right - ARect.Left do
      begin
        c.r := Round(c1.r + (c2.r - c1.r) * x / (ARect.Right - ARect.Left));
        c.g := Round(c1.g + (c2.g - c1.g) * x / (ARect.Right - ARect.Left));
        c.b := Round(c1.b + (c2.b - c1.b) * x / (ARect.Right - ARect.Left));
        Canvas.Brush.Color := c.Color;
        Canvas.FillRect(Rect(ARect.Left + x, ARect.Top,
                             ARect.Left + x + 1, ARect.Bottom));
      end;
    end;
  end;
  Canvas.Pen.Width := OldPenWidth; //restore old settings
  Canvas.Pen.Style := OldPenStyle;
end;
Das funktioniert soweit auch wunderbar, vor kurzem habe ich allerdings auf einigen Rechnern (die als Style Windows 7 Basic eingestellt hatten) gesehen dass die Zellen die mit einem Gradient gezeichnet werden sollten einfach nur schwarz sind.

Leider tritt dieses Problem nur sporadisch auf, d.h. dass es auch nicht auf allen Rechnern mit diesem Style auftritt und ich es bei mir auch noch nicht reproduzieren konnte.

Kennt vielleicht jemand von euch dieses Problem oder kann sich vorstellen woran es liegt?

PS: Die Werte mit denen ich die Funktion aufrufe
Color1: clWhite
Color2: $0090EE90 { Hellgrün }
RectHeight: 12
GradientOrientation: goVertical


MfG.
pHL
  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 07:30 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 by Thomas Breitkreuz