社区
C#
帖子详情
如何通过代码获知Form上有哪些控件?
sarmoo
2003-01-09 05:09:47
例如:一个自制控件,需要使用Form的ImageList,但怎样才能取到Form的这个ImageList?
...全文
93
10
打赏
收藏
如何通过代码获知Form上有哪些控件?
例如:一个自制控件,需要使用Form的ImageList,但怎样才能取到Form的这个ImageList?
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
10 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
project
2003-01-10
打赏
举报
回复
啊!来晚了。做一个ImageList的属性是正确的方法。
sarmoo
2003-01-10
打赏
举报
回复
OK!我试了一下,只要设置了这个属性,当Form中增加ImageList时,控件的这个属性的列表就会自动把这个新的ImageList增加进去。
原来这么简单,我把它想的太复杂了。
谢谢各位的回答!
准备结贴!
TheAres
2003-01-09
打赏
举报
回复
To sarmoo (Echo):
ImageList并不是继承自Control,所以通过Controls来判断根本方向不对.
你可以在你的控件中定义一个 MyImageList属性,来在Form中创建这个控件的时候,对这个属性赋值.
public class MyControl
{
private ImageList _imageList;
public MyImageList
{
set { _imageList = value;} //你也可以在这里写其他的处理
get { return _imageList;}
}
}
使用的时候,
MyControl c = new MyControl();
c.MyImageList = this.imageList1; //this是指Form
ssdjmcj8048
2003-01-09
打赏
举报
回复
try 判断一下不就可以了,其实不光有Component的问题,Com控件也有问题。
sarmoo
2003-01-09
打赏
举报
回复
当然,这个是在我的 class MyControl:Control内的一个属性。
sarmoo
2003-01-09
打赏
举报
回复
public ImageList ImageList
{
get
{
foreach(ImageList item in this.Parent.Controls)
{
if(item!=null)
imageList=item;
}
imageList;
}
}
我改写了,不过总觉得似乎有问题…………
sheep2002
2003-01-09
打赏
举报
回复
private ImageList _image=new ImageList();
public ImageList Image
{
set
{
_image=value;
}
get
{
return _image;
}
}
sarmoo
2003-01-09
打赏
举报
回复
系统提示:
Cannot convert type 'System.Windows.Forms.Control' to 'System.Windows.Forms.ImageList'
呵呵!
poetc
2003-01-09
打赏
举报
回复
foreach(Control item in this.controls)
{
if(item.GetType==(new ImageList()).GetType())
//...
}
henryfan1
2003-01-09
打赏
举报
回复
foreach(Control item in this.controls)
{
if(item.name=="ImageList1")
userControl.image=(ImageList)item
}
后台如何通过Request取得多个含有相同name的
控件
的值?
在Asp.net开发中,所有html
控件
的值都是可以在服务器端用后台
代码
的Request[name]来获取其值的。但如果有多个相同name的Html
控件
提交到后台,怎么分别取各个
控件
的值呢?而多数情况下这些
控件
的个数是不定的。 ...
ACCESS窗体中图表
控件
按条件使用
代码
设定柱图颜色
本文介绍了如何使用
代码
,按照条件设定图表
控件
柱图的颜色的方法。
后台如何通过Request取得多个含有相同name的
控件
的值?html input name 相同 取值 数组
在Asp.net开发中,所有html
控件
的值都是可以在服务器端用后台
代码
的Request[name]来获取其值的。但如果有多个相同name的Html
控件
提交到后台,怎么分别取各个
控件
的值呢?而多数情况下这些
控件
的个数是不定的。 例如...
用win
form
实现的类似于WPF中PopUp
控件
的一段
代码
用win
form
实现的类似于WPF中PopUp
控件
的一段
代码
using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Linq; using System.Runtime.InteropServices...
MSComm
控件
的使用方法1-2
如果CommPort属性设置为无效的端口号,在你试图打开端口时,MSComm
控件
将产生error68(Device unavailable)错误。如果你的硬件设备不支持Settings属性中的一些设置,则你的硬件工作或许不正确。当你使用奇偶校验位...
C#
110,533
社区成员
642,574
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章