Board index » delphi » How to change background color in application?

How to change background color in application?

Hello,

Does you know how to change the background colour of the given example
program?
It's now white and i like to change it. But i can't find the solution.
Please help me!

Raymond

program Easy;

uses
   OWindows;

type
   TToepassing = object( TApplication )
      procedure InitMainWindow; virtual;
   end;

procedure TToepassing.InitMainWindow;
begin
   MainWindow := new( PWindow, init( nil,
      'a easy program' ) );
end;

var
  Toepassing : TToepassing;

begin
   Toepassing.Init( 'Easy' );
   Toepassing.Run;
   Toepassing.Done;
end.

 

Re:How to change background color in application?


Hi Raymond,
if you want to change the background color of your program you can use:
"textbackground(x)". The x means a constant between 0 and 7, each number for
another color, but you will know this. Make a loop with gotoxy(x,y) and set
the coursor to each point of the screen. Execute this loop before all other
procedures and try to avoid incompatibilities with other routines that set
the background to another color. You can establish text without problems
now, the background color will be kept.
It could look like this:

procedure setcolor;
var county, countx :integer
begin
county:=0;
countx:=0;
    repeat
    inc(county);
    inc(countx);
    gotoxy(countx,county);
    TextBackground(1); {that sets a blue background)
    writeln('');
    until county=80; {or another number, it appends of your windowsize}
end;

There is also another possibility: If you use the Unit "Graph" you can work
with SETBKCOLOR(color), and SETCOLOR(color)!
color has the same constants as Textbackground. SETBKCOLOR sets anew
backgroundcolor and SETCOLOR a new textcolor. (It's the better way than the
above described. And more professional)

I hope I could help you. Have a lot of fun

Mischa

Other Threads