繁体   English   中英

如何更改或添加图片到staffdotnet.collapsiblepanel面板标题?

[英]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");
        }
    }
}

使用此示例(替换您自己的图像),产生了以下输出:

CollapsiblePanelTest-Form1

但是,这可能不是您要进行的最佳更改(将整个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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM