[英]How to change or add an image to staffdotnet.collapsiblepanel panel title?
我正在使用WinForms和.Net 2.0,并且正在使用staffdotnet.collapsiblepanel dll创建可折叠面板,并且我想在面板标题中添加背面图像。 我已经可以在面板标题中更改背景颜色,但是我不知道如何对图像进行更改。
我认为您可以在StaffDotNot.CollapsiblePanel
库本身(在此处找到)进行较小更改的情况下完成此操作。
在CollapsiblePanel.Designer.cs
,您将在partial class
声明的末尾看到以下声明:
private System.Windows.Forms.Panel titlePanel;
private System.Windows.Forms.PictureBox togglingImage;
private System.Windows.Forms.ImageList collapsiblePanelImageList;
private System.Windows.Forms.Label lblPanelTitle;
您将需要修改声明private System.Windows.Forms.Panel titlePanel;
到public System.Windows.Forms.Panel titlePanel;
。 这将允许您从库下载中包含的测试项目中执行以下代码:
namespace StaffDotNet.CollapsiblePanel.Test
{
public partial class frmTest : Form
{
public frmTest()
{
InitializeComponent();
this.collapsiblePanel1.titlePanel.BackgroundImage = Image.FromFile(@"GreenBubbles.jpg");
}
}
}
使用此示例(替换您自己的图像),产生了以下输出:
但是,这可能不是您要进行的最佳更改(将整个titlePanel
对象暴露给您的类)。 相反,将property
添加到CollapsiblePanel类定义中可能更有意义,该类获取和设置背景图像(同时将titlePanel
成员保留为private
)
//CollapsiblePanel.cs
#region Properties
...
/// <summary>
/// Gets or sets the the background image used in the panel title
/// </summary>
[Category("Collapsible Panel")]
[Description("Gets or sets the background image used in the panel title")]
[DisplayName("Panel Title Background Image")]
public Image PanelBackgroundImage
{
get { return titlePanel.BackgroundImage; }
set { titlePanel.BackgroundImage = value; }
}
#endregion
//frmTest.cs
namespace StaffDotNet.CollapsiblePanel.Test
{
public partial class frmTest : Form
{
public frmTest()
{
InitializeComponent();
this.collapsiblePanel1.PanelBackgroundImage = Image.FromFile(@"GreenBubbles.jpg");
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.