首页 > 解决方案 > 在 C# 中将图像添加到面板

问题描述

我正在尝试将音乐笔记的图像添加到已经存在的面板中。我已经为图像创建了路径:

String NoteImage_path = Environment.CurrentDirectory + @"\Notes-Images\";

我尝试使用以下代码行将图像添加到面板:

this.panel2.Controls.Add(this.NoteImage_path);

但我无法将字符串转换为 System.Windows.Form.Control。

我该如何解决这个问题?任何帮助将不胜感激。谢谢!

标签: c#imagepanel

解决方案


设置面板的背景图片

panel2.BackgroundImage = Image.FromFile(NoteImage_path);

推荐阅读