Mega Code Archive

 
Categories / Delphi / Examples
 

Changing the tdbnavigator button images

Question: How can I change the TDBNavigator button images? Answer: Provide bitmap files 'first.bmp' etc (see code below; it assumes that the bitmaps are in the directory where the .exe file resides) and use the procedure ChangeDBNavImage like this: ChangeDBNavImage(DBNavigator1); The code looks through the child objects for the TNavButton and assigns each bitmap. procedure ChangeDBNavImage(DBnav: TDbNavigator); var i: integer; tempGlyph: TBitmap; ExePath: string; begin { ChangeDBNavImage } ExePath := ExtractFilePath(Application.ExeName); tempGlyph := TBitmap.Create; try with DBnav do begin for i := 0 to ControlCount-1 do begin if Controls[i].ClassName='TNavButton' then begin case TNavButton(Controls[i]).index of nbFirst: tempGlyph.LoadFromFile(ExePath+'first.bmp'); nbPrior: tempGlyph.LoadFromFile(ExePath+'previous.bmp'); nbNext: tempGlyph.LoadFromFile(ExePath+'Next.bmp'); nbLast: tempGlyph.LoadFromFile(ExePath+'Last.bmp'); nbInsert: tempGlyph.LoadFromFile(ExePath+'Insert.bmp'); nbDelete: tempGlyph.LoadFromFile(ExePath+'Delete.bmp'); nbEdit: tempGlyph.LoadFromFile(ExePath+'Edit.bmp'); nbPost: tempGlyph.LoadFromFile(ExePath+'Post.bmp'); nbCancel: tempGlyph.LoadFromFile(ExePath+'Cancel.bmp'); nbRefresh: tempGlyph.LoadFromFile(ExePath+'Refresh.bmp'); end; { case TNavButton(Controls[i]).index } TNavButton(Controls[i]).Glyph := tempGlyph; // <-- Assign the loaded bitmap end; { Controls[i].ClassName='TNavButton' } end; { for i } end; { with DBnav } finally tempGlyph.Free; end; { try } end; { ChangeDBNavImage }