| How to enhance the functionality of a TDBgrid component using colors | ||||||
|
Adding color to your database grids will enhance the appearance and differentiate the importance of certain rows or columns within the database. Since the DBGrid is a great user interface tool for displaying data, this article will focus on questions like "How do I change the color of particular row / column / cell in a DBGrid?" Preparations Note: if you do not wont to work with the BDE, consider the chapters of the Free Database Course For Beginner Delphi Developers - Focus on ADO. Coloring Columns We will accomplish this through TColumns property of the grid. Select the grid component in the form and invoke the Columns editor by double clicking on the grid's Columns property in the Object Inspector. For more information on Columns editor look for "Columns editor: creating persistent columns" in your Delphi help files. Now, everything you have to do is to specify the background color of the cells of the particular column. For text foreground color, see the font property. This is what I have done, after few clicks... You have to agree that this is much better that the standard black'n'white grid (of course, use colors if you really need them).
Coloring Rows This technique demonstrates how to dynamically change the color of text in a DBGrid:
Next technique demonstrates how to dynamically change the color of row in a DBGrid:
Coloring Cells
Conclusion How about graphics?
| ||||||
|
Sunday, February 10, 2008
Coloring the DBGrid
Setting Default Printer di Delphi
procedure SetDefaultPrinter(PrinterName: String) ;
var
___j: Integer;
___Device : PChar;
___Driver : Pchar;
___Port : Pchar;
___HdeviceMode: Thandle;
___aPrinter : TPrinter;
begin
___Printer.PrinterIndex := -1;
___getmem(Device, 255) ;
___getmem(Driver, 255) ;
___getmem(Port, 255) ;
___aPrinter := TPrinter.create;
___for j := 0 to Printer.printers.Count-1 do
___begin
______if Printer.printers[j] = PrinterName then
______begin___
_________aprinter.printerindex := i;
_________aPrinter.getprinter(device, driver, port, HdeviceMode) ;
_________StrCat(Device, ',') ;___
_________StrCat(Device, Driver ) ;
_________StrCat(Device, Port ) ;
_________WriteProfileString('windows', 'device', Device) ;
_________StrCopy( Device, 'windows' ) ;
_________SendMessage(HWND_BROADCAST, WM_WININICHANGE,0, Longint(@Device)) ;
______end;
___end;
___Freemem(Device, 255) ;
___Freemem(Driver, 255) ;
___Freemem(Port, 255) ;___
___aPrinter.Free;
end;
var
___j: Integer;
___Device : PChar;
___Driver : Pchar;
___Port : Pchar;
___HdeviceMode: Thandle;
___aPrinter : TPrinter;
begin
___Printer.PrinterIndex := -1;
___getmem(Device, 255) ;
___getmem(Driver, 255) ;
___getmem(Port, 255) ;
___aPrinter := TPrinter.create;
___for j := 0 to Printer.printers.Count-1 do
___begin
______if Printer.printers[j] = PrinterName then
______begin___
_________aprinter.printerindex := i;
_________aPrinter.getprinter(device, driver, port, HdeviceMode) ;
_________StrCat(Device, ',') ;___
_________StrCat(Device, Driver ) ;
_________StrCat(Device, Port ) ;
_________WriteProfileString('windows', 'device', Device) ;
_________StrCopy( Device, 'windows' ) ;
_________SendMessage(HWND_BROADCAST, WM_WININICHANGE,0, Longint(@Device)) ;
______end;
___end;
___Freemem(Device, 255) ;
___Freemem(Driver, 255) ;
___Freemem(Port, 255) ;___
___aPrinter.Free;
end;
Tuesday, February 5, 2008
Change Printer Orientation Setup
You cannot change printer property during print document. But you can interrupt print process to change properties and run print again from the necessary line. uses Printers;
...
procedure TForm1.Button1Click(Sender: TObject) ;
var
___F, F2: TextFile;
___k, j: Integer;
begin
___AssignPrn(F) ;
___Rewrite(F) ;
___Writeln(F, RichEdit1.Lines[0]) ;
___for k:=1 to RichEdit1.Lines.Count-1 do
___begin
______if Printer.PageNumber<2>then
_________Writeln(F, RichEdit1.Lines[k]) ;
______if Printer.PageNumber>1 then
______begin
_________CloseFile(F) ;
_________Break;
______end;
___end;
___AssignPrn(F2) ;
___Printer.Orientation:=poLandscape;
___Rewrite(F2) ;
___for j:=i to RichEdit1.Lines.Count-1 do
______Writeln(F2, RichEdit1.Lines[j]) ;
___CloseFile(F2) ;
end;
...
procedure TForm1.Button1Click(Sender: TObject) ;
var
___F, F2: TextFile;
___k, j: Integer;
begin
___AssignPrn(F) ;
___Rewrite(F) ;
___Writeln(F, RichEdit1.Lines[0]) ;
___for k:=1 to RichEdit1.Lines.Count-1 do
___begin
______if Printer.PageNumber<2>then
_________Writeln(F, RichEdit1.Lines[k]) ;
______if Printer.PageNumber>1 then
______begin
_________CloseFile(F) ;
_________Break;
______end;
___end;
___AssignPrn(F2) ;
___Printer.Orientation:=poLandscape;
___Rewrite(F2) ;
___for j:=i to RichEdit1.Lines.Count-1 do
______Writeln(F2, RichEdit1.Lines[j]) ;
___CloseFile(F2) ;
end;
Subscribe to:
Posts (Atom)