You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Delphi代码在TMS Web Core中为Form添加背景图片

在TMS Web Core中通过Delphi代码为Form设置背景图片

你可以在Form的OnCreate事件中直接操作Form对应的HTML元素样式来实现背景图片加载,具体代码如下:

procedure TForm1.WebFormCreate(Sender: TObject);
begin
  // 设置背景图片路径
  WebForm.ElementHandle.style.setProperty('background-image', 'url("material.jpeg")');
  
  // 可选:添加背景图的优化样式,让图片适配容器
  WebForm.ElementHandle.style.setProperty('background-repeat', 'no-repeat');
  WebForm.ElementHandle.style.setProperty('background-size', 'cover');
  WebForm.ElementHandle.style.setProperty('background-position', 'center center');
end;

注意事项:

  • 确保图片文件material.jpeg放在项目的www目录下,这样编译后Web应用才能正确访问到该资源。
  • WebForm.ElementHandle指向Form对应的HTML容器元素,通过它的style.setProperty方法可直接设置CSS属性,和你提到的原生CSS写法效果完全一致。
  • GetFormImage仅用于捕获Form当前内容的截图,确实无法用来设置背景图片,上面的方法才是适配需求的正确实现方式。

内容的提问来源于stack exchange,提问作者Gorhin Stroebel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 08:37:02