How to make a gradient backgound on a form

I need to make a gradient form for one app I'm developping. I made one, but when i tried
to use my source with 26 colors it dind't work.
I need some piece of code that works on 8bit,16bit,24bit and 32bit(if possible it would be
of it worked also on 4bit-16 colors

IDEAS??

thanks

                 LR
LVL 1
lfrodriguesAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TheNeilCommented:
Try doing something along the lines of the following:

VAR
  r_step, g_step, b_step : REAL;
  r, g, b, n : INTEGER;
BEGIN
  r_step := (r1 - r2) / bmpBackdrop.Height;
  g_step := (g1 - g2) / bmpBackdrop.Height;
  b_step := (b1 - b2) / bmpBackdrop.Height;

  bmpBackdrop.PixelFormat := pf8bit;

  FOR n := 0 TO bmpBackdrop.Height
  DO
  BEGIN
    r := ROUND(r1 + n * r_step);
    g := ROUND(g1 + n * g_step);
    b := ROUND(b1 + n * b_step);
    bmpBackdrop.Canvas.Pen.Color := RGB(r, g, b);
    bmpBackdrop.Canvas.MoveTo(0, n);
    bmpBackdrop.Canvas.LineTo (bmpBackdrop.Width, n);
  END;
END;

You simply need to supply the two colours to gradiate between (r1, g1, b1 and r2, g2, b2) and it should work. You can also change the colour depth and it should still work fine with Windows picking the nearest colour that it can.

The Neil
0
intheCommented:
Hi
here's a way to try:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls;

type
  TForm1 = class(TForm)
    Image1: TImage;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    procedure PaintBackGround;
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}
procedure TForm1.PaintBackGround;
 var Clr1, Clr2: TColor; RGBFrom: array[0..2] of Byte; RGBDiff: array[0..2] of Integer;
  ColorBand: TRect; I: Integer; R, G, B: Byte; begin
 with Image1 do begin
  Height := Screen.Height;
  Width := Screen.Width;
  Left := 0;
  Top := 0;
  Clr1 := clNavy;
  Clr2 := clMaroon;
  RGBFrom[0] := GetRValue (ColorToRGB(Clr1));
  RGBFrom[1] := GetGValue (ColorToRGB(Clr1));
  RGBFrom[2] := GetBValue (ColorToRGB(Clr1));
  RGBDiff[0] := GetRValue (ColorToRGB(Clr2)) - RGBFrom[0];
  RGBDiff[1] := GetGValue (ColorToRGB(Clr2)) - RGBFrom[1];
  RGBDiff[2] := GetBValue (ColorToRGB(Clr2)) - RGBFrom[2];
  ColorBand.Left := 0;
  ColorBand.Right := Width;
  for I := 0 to $ff do begin
   ColorBand.Top := MulDiv (I, Height, $100);
   ColorBand.Bottom := MulDiv (I + 1, Height, $100);
   R := RGBFrom[0] + MulDiv (I, RGBDiff[0], $ff);
   G := RGBFrom[1] + MulDiv (I, RGBDiff[1], $ff);
   B := RGBFrom[2] + MulDiv (I, RGBDiff[2], $ff);
   Canvas.Brush.Color := RGB (R, G, B);
   Canvas.FillRect (ColorBand); end; end; end;

procedure TForm1.FormCreate(Sender: TObject);
begin
paintbackground;
end;

end.
0
drnadeemCommented:
How about this one ?

gradientfill(canvas,clientrect,clred,clblue,true);



Add Chart to uses clause.
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

intheCommented:
drnadeem ,
dont you think you should have posted comment only?

0
drnadeemCommented:
Sorry inthe, wasn't giong to steal your points. :)

0
lfrodriguesAuthor Commented:
inthe's anwser is by far the best. So inthe post a anwser so i can credit you
0
intheCommented:
Thankyou :-)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.