自定义控件中的图片问题

老譚山菜 2003-10-09 05:56:33
自定义控件中使用了图片按钮,定义了一个属性来设置该按钮图片的路径,
请问:要如何做,才能让图片在设置了路径属性之后可以在设计视图中显示?
...全文
37 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
老譚山菜 2003-10-11
  • 打赏
  • 举报
回复
一个图片按钮通过以上可以实现。
如果控件需要多个图片按钮呢?
好像就不行了
saucer 2003-10-11
  • 打赏
  • 举报
回复
make sure the image is in web app,


using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Web.UI.Design;
using System.Drawing.Design;

namespace CustomControls
{
[ToolboxData("<{0}:MyImageButton runat=server></{0}:MyImageButton>")]
public class MyImageButton : System.Web.UI.WebControls.WebControl
{
ImageButton ib;
protected override void CreateChildControls()
{
ib = new ImageButton();
Controls.Add(ib);
}

[EditorAttribute(typeof(System.Web.UI.Design.ImageUrlEditor), typeof(UITypeEditor))]
public string ImageUrl
{
get { EnsureChildControls(); return ib.ImageUrl;}
set { EnsureChildControls(); ib.ImageUrl = value;}
}

}
}
老譚山菜 2003-10-11
  • 打赏
  • 举报
回复
还是不能在设计视图中显示
只能在运行之后显示,郁闷
saucer 2003-10-10
  • 打赏
  • 举报
回复
if you are adding the image button in CreateChildControls(), make sure you call EnsureChildControls() in the property's set clause, for example

ImageButton ib;
protected override void CreateChildControls()
{
ib = new ImageButton();
Controls.Add(ib);
}

[EditorAttribute(typeof(System.Web.UI.Design.ImageUrlEditor), typeof(UITypeEditor))]
public string ImageUrl
{
get { EnsureChildControls(); return ib.ImageUrl;}
set { EnsureChildControls(); ib.ImageUrl = value;}
}

老譚山菜 2003-10-10
  • 打赏
  • 举报
回复
就是因为页面的路径是不确定的,所以才定义了一个路径属性,允许设置
benbenyi 2003-10-09
  • 打赏
  • 举报
回复
自定义控件中图片的路径,要根据自定义控件所要放置的页面的路径来写,这样运行时才能看到

62,041

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧