【问题标题】:C# adding image property to controlboxC#将图像属性添加到控制框
【发布时间】:2014-01-26 06:50:44
【问题描述】:

我的 userControl1.cs 包含一个文本框和一个图片框 如何向我的类添加属性以允许它从 url 字符串中获取图片

这是我目前所拥有的

    public partial class UserControl1 : UserControl
{
    public UserControl1()
    {
        InitializeComponent();
    }

    public override string Text
    {
        get
        {
            return textBox1.Text;
        }

        set
        {
            textBox1.Text = value;
        }
    }

}

【问题讨论】:

    标签: c#


    【解决方案1】:

    这就是你添加属性的方式,

    public Image PictureFromWeb  { get; set;}
    

    但是有更好的方法

    内置的PictureBox.Load(string URL) 方法“将 ImageLocation 设置为指定的 URL 并显示指定的图像。” (从 .NetFramework 2 开始)
    引用自This Answer -- 点赞他的回答

    【讨论】:

    • 所以我试图让用户控件中的图片框获取 url 并将其转换为图片,我使用 userControl11.UserPicture = tweet.Creator.DownloadProfileImage(token); DownloadProfileImage 检索 url 字符串。我将 FamilyPicture 更改为 UserPicture
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-31
    • 1970-01-01
    • 1970-01-01
    • 2013-01-09
    相关资源
    最近更新 更多