无法处理TableLayoutPanel中的PictureBox.DrawImage

时间:2018-06-07 07:45:52

标签: c#

onStatus

如果我在PictureBox中执行此操作(仅放置在窗体上),它可以正常工作但在TableLayoutPanel中它不会

也尝试了

.onStatus(HttpStatus::is4xxClientError, res -> {
  res.toEntity(String.class).subscribe(
    entity -> log.warn("Client error {}", entity)
   );
   return Mono.error(new HttpClientErrorException(res.statusCode()));}
 )

也尝试了

img = Image.FromFile(@"images\dcw.png");
Graphics g = tabPanl.GetControlFromPosition(1, 1).CreateGraphics();
g.DrawImage(img,
      new Rectangle(0, 0, 50, 50),
      new Rectangle(img.Width / 2 - 25, img.Height / 2 - 25, 50, 50),
      GraphicsUnit.Pixel);

所以我应该做其他事情

尝试建立一个桌面游戏,在运行时绘制图形 - 玩家选择的不同图像

托尼先生

2 个答案:

答案 0 :(得分:2)

它实际上是绘制,但然后Paint事件清除它。如果要使其持久化,则必须将代码添加到PictureBox的Paint事件中。

 Image img = Image.FromFile(@"images\dcw.png");
 int picBoxIndex = tabPanl.Controls.GetChildIndex(picBox1x1);
tabPanl.Controls[picBoxIndex].Paint += (s,e) =>{
   e.Graphics.DrawImage(img,
            new Rectangle(0, 0, 50, 50),
            new Rectangle(img.Width / 2 - 25, img.Height / 2 - 25, 50, 50),
            GraphicsUnit.Pixel);
};

但是,为什么不使用PictureBox.BackgroundImage属性?

答案 1 :(得分:0)

好吧,我没有使用BackgroundImage,因为我无法将一个(循环)定义的图像部分放在这个背景图像中;这也是我的想法,但我也无法处理这个问题

我尝试使用Paint-Event,thx到目前为止 - >它运作良好