用戶自定義控件顏色:用ColorDialog自定義顏色,並從配置文件中讀取和寫入

ColorToString(ColorDialog.Color)

StringToColor('$800080')

實現自定義顏色

 

procedure TFormBreakSiteStat.SpeedButton1Click(Sender: TObject);
var
  lIniPath: string;
  ini: TIniFile;
begin
  lIniPath:= ExtractFilePath(Application.ExeName)+'ProjectCFMS_Client.ini';
  ini:= TIniFile.Create(lIniPath);
  try
    if ColorDialog.Execute then
    begin
      if RBCaption.Checked then
      begin
        ini.WriteString('Color','CaptionColor',ColorToString(ColorDialog.Color));
        FG_RepShow.CaptionColor:= ColorDialog.Color;
      end;
      if RBLabel.Checked then
      begin
        ini.WriteString('Color','LabelColor',ColorToString(ColorDialog.Color));
        FG_RepShow.LabelColor:= ColorDialog.Color;
      end;
      if RBData.Checked then
      begin
        ini.WriteString('Color','DataColor',ColorToString(ColorDialog.Color));
        FG_RepShow.DataColor:= ColorDialog.Color;
      end;
      if RBBackground.Checked then
      begin
        ini.WriteString('Color','BackgroundColor',ColorToString(ColorDialog.Color));
        FG_RepShow.Color:= ColorDialog.Color;
      end;
    end;
  finally
    ini.Free;
  end;
end;

procedure TFormBreakSiteStat.GetRepColor;
var
  lIniPath: string;
  ini: TIniFile;
begin
  lIniPath:= ExtractFilePath(Application.ExeName)+'ProjectCFMS_Client.ini';
  if FileExists(lIniPath) then
  begin
    ini:= TIniFile.Create(lIniPath);
    try
      FG_RepShow.CaptionColor:= StringToColor(ini.ReadString('Color','CaptionColor','clPurple'));
      FG_RepShow.LabelColor:= StringToColor(ini.ReadString('Color','LabelColor','clSkyBlue'));
      FG_RepShow.DataColor:= StringToColor(ini.ReadString('Color','DataColor','clTeal'));
      FG_RepShow.Color:= StringToColor(ini.ReadString('Color','BackgroundColor','clInactiveCaptionText'));
    finally
      ini.Free;
    end;
  end;

 
end;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章