const
  bgCount=3;

var
  bgIndex:integer;
  section:string;
  
procedure RefreshPreview;
begin
  Beginupdate;
  bgIndex:=((bgIndex-1) mod bgCount)+1;
  case bgIndex of 
    1: section:='blue';  
    2: section:='grey';  
    3: section:='orange';  
  end;
  imgbg.FileName:=WidgetPath+'images\'+section+'\calendar_single_orange.png';
  lblIndex.caption:=inttostr(bgIndex)+'/'+inttostr(bgCount);
  Endupdate;
end;

//读取配置
procedure InitIni;
var
  inifn:TIniFile;
begin
  bgIndex:=GetSettingInt('bgIndex',1);
  lblIndex.caption:=format('%d/%d',[bgIndex,bgCount]);
  RefreshPreview;
end;

//保存配置
procedure SaveIni;
begin
  SetSetting('bgIndex',bgIndex);
end;

//--- Widget设置窗口初始化事件，当打开Widget设置窗口时会触发此事件 ---
procedure OnSettingInit;
begin
  Beginupdate;
  InitIni;
  Endupdate;
end;

//--- 按下设置窗口的确定按钮时，触发此事件 ---
//通过设置返回值来改变是否允许确认,当result为False时不关闭设置窗口
function OnSettingClose(iResult);
begin
  result:=true;
  if Result then
    SaveIni;
end;
