我是 Delphi 新手,我需要一些帮助。
我有一个程序,一个背景颜色更改器(mutator),带有一个TColorDialog
。否则效果很好,但是当我关闭 ColorDialog 而不从中选择颜色时,就会出现问题。然后背景变成黑色,并且还在 .ini
文件中将黑色保存为颜色“0”。
我的代码:
procedure TEinstellungenF.BtnBackgroundClick(Sender: TObject);
var filename:String;
ini:TIniFile;
begin // Speichert die im ColorDialog ausgewählten Background Farben in der Ini
filename := ExtractFilePath(ParamStr(0)) + 'Einstellungen.ini';
ini := TIniFile.Create(filename);
ColorDialog1.Execute();
try
ini.WriteInteger('Farben','Hintergrundfarbe', ColorDialog1.Color);
finally
ini.Free;
end;
FrmMain.Color := TColor(Ini.ReadInteger('Farben','Hintergrundfarbe',ColorDialog1.Color));
Color := TColor(Ini.ReadInteger('Farben','Hintergrundfarbe',ColorDialog1.Color));
end;```
最佳答案
检查ColorDialog1.Execute
的返回值并采取相应措施。
来自文档:
Execute opens the color-selection dialog, returning true when the user selects a color and clicks OK, or false when the user cancels.
关于Delphi - Colordialog 选择黑色作为颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69193939/