Jump to content

How to change TunimPanel Background Image at Runtime?


newsanti

Recommended Posts

procedure TMainmForm.UnimFormCreate(Sender: TObject);
begin
  var oPanel:= UnimContainerPanel1;
//  TuniLayoutConfig(oPanel.LayoutConfig).Cls:= 'mainbackground';  // work OK.
  var oJS:= oPanel.JSInterface;
  oJS.JSAddListener('afterrender',
  oJS.JSFunction('sender',
  'document.body.style.background=''url("/files/mainlogo2.jpg");repeat scroll 0% 0%'''));  //Mainlogo2.jpg not shown.
end;

 

FormBackground.zip

Link to comment
Share on other sites

Hello,

I don't know where you got it from:

43 minutes ago, newsanti said:

oJS.JSAddListener('afterrender',
  oJS.JSFunction('sender',
  'document.body.style.background=''url("/files/mainlogo2.jpg");repeat scroll 0% 0%'''));  //Mainlogo2.jpg not shown.

 

In your case this will be correct:

procedure TMainmForm.UnimFormCreate(Sender: TObject);
begin
  var oPanel:= UnimContainerPanel1;
//  TuniLayoutConfig(oPanel.LayoutConfig).Cls:= 'mainbackground';
  var oJS:= oPanel.JSInterface;
  oJS.JSAddListener('painted',
  oJS.JSFunction('sender',
  'sender.bodyElement.setStyle(''background'', ''url(/files/mainlogo2.jpg) repeat scroll 0% 0%'')'));
end;

 

  • Like 1
Link to comment
Share on other sites

19 minutes ago, Sherzod said:

Hello,

I don't know where you got it from:

 

In your case this will be correct:

procedure TMainmForm.UnimFormCreate(Sender: TObject);
begin
  var oPanel:= UnimContainerPanel1;
//  TuniLayoutConfig(oPanel.LayoutConfig).Cls:= 'mainbackground';
  var oJS:= oPanel.JSInterface;
  oJS.JSAddListener('painted',
  oJS.JSFunction('sender',
  'sender.bodyElement.setStyle(''background'', ''url(/files/mainlogo2.jpg) repeat scroll 0% 0%'')'));
end;

 

how to set cover of image with setstyle?
  var oPanel:= UnimContainerPanel1;
//  TuniLayoutConfig(oPanel.LayoutConfig).Cls:= 'mainbackground';
  var oJS:= oPanel.JSInterface;
  oJS.JSAddListener('painted',
  oJS.JSFunction('sender',
  'sender.bodyElement.setStyle(''background'', ''url(/files/mainlogo2.jpg)'')'));

  oJS.JSAddListener('painted',
  oJS.JSFunction('sender',
  'sender.bodyElement.setStyle(''background-size'', ''cover'')'));

Can coding in single command?
 

Link to comment
Share on other sites

1 minute ago, Sherzod said:

What exactly?

  if oPanelX is TUniCustomContainerPanel then
     begin
        var oPanel:= TUniCustomContainerPanel(oPanelX);
        if Assigned(oPanel) then
          begin
            var oJS:= oPanel.JSInterface;
            oJS.JSAddListener('painted',
            oJS.JSFunction('sender',
            'sender.bodyElement.setStyle(''background'', ''url('+S+')'')'));

            oJS.JSAddListener('painted',
            oJS.JSFunction('sender',
            'sender.bodyElement.setStyle(''background-repeat'', ''no-repeat'')'));

            oJS.JSAddListener('painted',
            oJS.JSFunction('sender',
            'sender.bodyElement.setStyle(''background-size'', ''100% 100%'')'));
          end;
     end;
I try setting in one command.

Link to comment
Share on other sites

13 minutes ago, newsanti said:

I try setting in one command.

Well,

2 hours ago, Sherzod said:
oJS.JSAddListener('painted',
  oJS.JSFunction('sender',
  'sender.bodyElement.setStyle(''background'', ''url(/files/mainlogo2.jpg) repeat scroll 0% 0%'')'));

This is it in one line of code!

  • Thanks 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...