Forum > LCL
[SOLVED] searching for the Icons used by function dialogs.MessageDlg
Hartmut:
I want to use some of the Icons, which can be displayed by function dialogs.MessageDlg(), in my own dialogs, but I cannot find them. Are they part of the Lazarus installation (on Windows or Linux) or are they only part of the Operation System?
Please can someone point me to the location, where I can find the files with this Icons?
I use Lazarus 2.0.10 and I have Windows 7 and 10 (and XP ;-) and Ubuntu 18.04.
Thanks in advance.
winni:
Hi!
Have a look at lazarus/images and the subdirectories.
Winni
wp:
In unit Dialogs you find a function GetDialogIcon(ID) which returns the icon for the specified ID where ID is either idDialogWarning, idDialogError, idDialogInfo, idDialogConfirm or idDialogShield as declared in unit LCLType:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Button1Click(Sender: TObject);var img: TCustomBitmap;begin img := GetDialogIcon(idDialogError); // or idDialogWarning, idDialogInfo, idDialogConfirm, idDialogShield try Image1.Picture.Assign(img); finally img.Free; end;end;
Note, however, that for better high-dpi support, this part of the LCL recently has been reworked by Ondrej who marked this function as deprecated now. There is a new unit, DialogRes, with an auto-generated ImageList named "DialogGlyphs" in which the method "DialogIcon[ID]" returns the image index of some specific ID. And note also, that the TImage has been extended to support an Images imagelist and an ImageLindex. Therefore, the above code should be replaced in the future (in Laz 2.3.+) by
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Button2Click(Sender: TObject);begin Image1.Images := DialogGlyphs; Image1.ImageIndex := DialogGlyphs.DialogIcon[idDialogError];end;
Hartmut:
Thank you winni for that info. In folder lazarus/images/states/ I found some Icons which are not the original ones, but usable.
Hello wp again. Thank you very much for that suggestion and demo. With it I could easily load the original Icons from Windows and Linux. I saved them by adding
Image1.Picture.SaveToFile('filename.png');
because I want to use them via a resource file.
There is only one disadvantage: while the Icons saved in Linux are transparent, the Icons saved in Windows are not. When I display them, they have an ugly black background. I tried to avoid that by adding
Image1.Transparent:=true;
before the save-command, but this did not help.
I'm a beginner to Graphics. Is it possible to save the Windows Icons with a transparent background?
wp:
Current release (deprecated):
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses LCLType; procedure TForm1.Button1Click(Sender: TObject);var img: TCustomBitmap; png: TCustomBitmap;begin img := GetDialogIcon(idDialogError); try png := TPortableNetworkGraphic.Create; try png.Assign(img); png.SaveToFile('idDialogError.png'); finally png.Free; end; finally img.Free; end;end;
Laz/main + future releases:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses DialogRes; procedure TForm1.Button2Click(Sender: TObject);var png: TPortableNetworkGraphic; idx: Integer;begin png := TPortableNetworkGraphic.Create; try idx := DialogGlyphs.DialogIcon[idDialogError]; DialogGlyphs.GetBitmap(idx, png); png.SaveToFile('idDialogError_new.png'); finally png.Free; end;end;
Navigation
[0] Message Index
[#] Next page