win form中imagelist资源问题?

towhere 2003-08-25 01:17:33

偶做系统,
在windows form 中:
多个界面都有toolbar 应用到imagelist
每个界面都有一个imagelist控件,这样应该是很浪费资源,并且更改不容易,
能否有办法就像VC++中的一样应用一个imagelist 资源共享???

高手帮忙!!!
...全文
86 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
panyee 2003-08-25
  • 打赏
  • 举报
回复
我在程序中用过一个好方法, 现公布如下:

比如,在一个项目中有一个Form1和一个Form6,
在Form1中有imageList1资源, 可以通过这种方式访问, 让Form6中的toolbar访问Form1中的ImageList资源

//取Form1的资源
System.Resources.ResourceManager resource = new System.Resources.ResourceManager(typeof(Form1));
//取得imagelist1的资源流
System.Windows.Forms.ImageListStreamer imgliststream = ((System.Windows.Forms.ImageListStreamer)(resource.GetObject("imageList1.ImageStream")));
//给Form6中的ImageList赋值
ImageList imglist = new ImageList();
imglist.ImageStream = imgliststream;
toolBar1.ImageList = imglist;
//设置工具条图标索引
toolBar1.Buttons[0].ImageIndex = 0;
toolBar1.Buttons[1].ImageIndex = 1;
Showme005 2003-08-25
  • 打赏
  • 举报
回复
是的,重写一个类比较好!
zykj_2000 2003-08-25
  • 打赏
  • 举报
回复
同意snof
ps:snow wolf==>snof 历害
greenhill1 2003-08-25
  • 打赏
  • 举报
回复
可以专门写一个imagelist放图形的类,当你需要什么样的图形时就对该 imagelist进行重写图片存放地址!
雪狼1234567 2003-08-25
  • 打赏
  • 举报
回复
其实也不会啦,或者你可以单独写一个类,封装ImageList,然后在全部的类中去调用它
xiaodele 2003-08-25
  • 打赏
  • 举报
回复
static 类型试试

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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