DelphiStudent
DelphiStudent

Reputation: 394

Filling listview with gradient background color

iam trying to draw gradient Background over list view using GraphUtil , i have only problem with gradient position

here is my custom list view draw event

Var
  R: TRect;
begin
  // Full ListView
  SetRect(R, ARect.Left, ARect.Top, ARect.Right - ((ARect.Right-ARect.Left) div 2), ARect.Bottom );
  GradientFillCanvas(Sender.Canvas, panelemo.Color, clWhite, R, gdVertical); // GraphUtil
  SetRect(R, ARect.Right - ((ARect.Right-ARect.Left) div 2), ARect.Top, ARect.Right, ARect.Bottom );
  GradientFillCanvas(Sender.Canvas, panelemo.Color, clWhite, R, gdVertical);
  panelmeter.Color := panelemo.Color;

i want to draw gradient from right to left not from top to bottom like this image

enter image description here

Upvotes: 0

Views: 856

Answers (1)

Tom Brunberg
Tom Brunberg

Reputation: 21033

It is unclear what you actually want to have because what you say is different from what you show.

Anyhow, gdHorizontal means that the color is changing from StartColor to EndColor horizontally from left to right. In your image as if you would have specified white as start color and turqoise as end color. If you want to change the horizontal direction (to from right to left), you need to swap the colors.

Example of horizontal using code:

GradientFillCanvas(ListView1.Canvas, AColor, clWhite, R, gdHorizontal);

enter image description here

gdVertical means that the color is changing vertically, from top to bottom. If you want to change the vertical direction (to from bottom to top), you need to swap the colors.

Example of vertical using code:

GradientFillCanvas(ListView1.Canvas, AColor, clWhite, R, gdVertical);

enter image description here

The sliced result I think you refer to, is caused by the fact that you draw the gradient with two calls to GradientFillCanvas() once for each half of the TRect.

Upvotes: 2

Related Questions