【问题标题】:tablelayoutpanel won't change background imagetablelayoutpanel 不会改变背景图片
【发布时间】:2020-07-06 17:26:04
【问题描述】:

图片名是从ini文件中加载的,第一次设置背景没有任何问题。但是,当它根据动作从ini文件中加载另一个图像时,它不会设置不同的背景。

 var parser = new FileIniDataParser();
 IniData data = parser.ReadFile("configuration.ini");

 int panelRow = GetMyClass.toInt(data[config_PanelCount]["rowCount"]);
 int panelColl = GetMyClass.toInt(data[config_PanelCount]["collCount"]);
 string bckGround = data[config_PanelCount]["background"];
 tableStolovi.Controls.Clear();
 tableStolovi.BackgroundImage = null;
            

 string appPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
 Image bck = Image.FromFile(appPath + "\\" + bckGround);
 tableStolovi.BackgroundImage = bck;
 tableStolovi.BackgroundImageLayout = ImageLayout.Stretch;

如何为tablelayoutpanel每次设置背景

【问题讨论】:

  • 我不喜欢 tablelayoutpanel,因为您可以设置的属性数量非常有限。每次我尝试做一个 tablelayoutpanel 时,我都放弃了,而是创建了一个主面板并添加了我自己的子面板,它们看起来与布局面板完全一样,但没有无法更改背景图像的问题。
  • 调试问题。运行这段代码时bck 的值是多少?如果它在您加载它时起作用,而不是稍后,那么听起来问题出在 ini 文件上。 Ini 文件较旧,请改用设置属性。

标签: c# windows winforms tablelayoutpanel


【解决方案1】:

您可以在设置新背景后尝试刷新 tableLayoutPanel。

tableStolovi.Refresh();

【讨论】:

  • 很抱歉我发现了一个错误。该代码在另一个地方完美运行,我得到了错误的图片。对不起,再次感谢您的努力
猜你喜欢
  • 1970-01-01
  • 2018-02-03
  • 2017-10-11
  • 1970-01-01
  • 1970-01-01
  • 2021-03-21
  • 2015-03-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多