派生类的自定义属性问题(也许很简单)
基类为ComboBox
自定义属性其类型为ImageList
如下
public property ItemImageList() as Imagelist
get
return itemimagelist
end get
set (byval value as imagelist)
itemimagelist=value
end set
end property
在form中添加自定义combobox没有问题,my combobox的itemimagelist能自动列表出form中所有的imagelist,可是程序运行时以及为ItemImageList属性选择窗体中的ImageList控件时,提示属性无效,堆栈溢出异常。
请问这如何解决?
问题点数:20、回复次数:8Top
1 楼exboy(kuku)回复于 2006-03-12 00:57:07 得分 15
把 itemimagelist 改一下名称吧
VB.NET是不区大小写的Top
2 楼tu_long1234(想飞却飞不动的猪)回复于 2006-03-12 01:02:37 得分 0
晕
不知道你是开发的自定义web控件还是单机的类。
不过开发web控件的时候复杂的控件属性要自己自己进行状态管理,要自己实现istatemananger功能越多就要实现的接口就比较多。
如果是本地的类的话,感觉应该自己定义一些接口.
最好自己看msdn.这样一类的问题最好看msdn.要不你把你的整个程序贴出来吧,能帮尽量帮呵呵。
如果你问题要是解决了,记得告诉我。-=-
Top
3 楼programart_life(理论派)回复于 2006-03-12 01:03:07 得分 0
呵呵,这么晚了还没睡觉啊?
不是名称的问题。没有与ItemImageList重名的冲突。Top
4 楼programart_life(理论派)回复于 2006-03-12 01:07:52 得分 0
Imports System
Imports System.Windows.Forms
Public Class ImageComboBox
Inherits System.Windows.Forms.ComboBox
Public Property ItemImageList() As ImageList
Get
Return ItemImageList
End Get
Set(ByVal Value As ImageList)
ItemImageList= Value
End Set
End Property
Protected Overloads Sub OnDrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs)
Dim g As Graphics = e.Graphics
Dim r As Rectangle = e.Bounds
Dim imageSize As Size = ItemImageList.ImageSize
Dim fn As Font = Nothing
If (e.Index >= 0) Then
fn = Font()
Dim s As String = Items(e.Index).ToString 'ComboBox1.Items(e.Index).ToString
Dim sf As StringFormat = New StringFormat
sf.Alignment = StringAlignment.Near
If e.State = DrawItemState.NoAccelerator Or e.State = DrawItemState.NoFocusRect Then
'画条目背景
'e.Graphics.FillRectangle(New SolidBrush(Color.Red), r)
'绘制图像
ItemImageList.Draw(e.Graphics, r.Left, r.Top, e.Index)
'显示字符串
e.Graphics.DrawString(s, fn, New SolidBrush(Color.Black), r.Left + imageSize.Width, r.Top)
e.DrawFocusRectangle()
Else
ItemImageList.Draw(e.Graphics, r.Left, r.Top, e.Index)
e.Graphics.DrawString(s, fn, New SolidBrush(Color.Black), r.Left + imageSize.Width, r.Top)
e.DrawFocusRectangle()
End If
End If
End Sub
End Class
Top
5 楼programart_life(理论派)回复于 2006-03-12 01:09:51 得分 0
我想做个能选择图像的下拉列表控件。这样combobox就需要一个ImageList配合,所以需要一个属性来指定ImageList。上面是初步的程序Top
6 楼program_art()回复于 2006-03-12 08:51:58 得分 0
我已经把问题解决了,呵呵
要定义一个变量来储存属性值。唉,没办法,当新手就是这么痛苦。
这论坛真烦,自己的回复不能删除,不能修改。Top
7 楼wuyazhe(wyz&xyl)回复于 2006-03-12 09:09:53 得分 5
exboy(kuku) ( )说的就对了。
Public Property ItemImageList() As ImageList
Get
Return ItemImageList
End Get
Set(ByVal Value As ImageList)
ItemImageList= Value
End Set
End Property
这么定义叫做无限递归。Top
8 楼programart_life(理论派)回复于 2006-03-12 10:03:17 得分 0
to wuyazhe(我的宝贝叫阿刺)
是啊,可当时我没看懂他的意思,后来试着自己定义一个变量来存储属性值(忘记以前vb里就是这么干的了)才明白了。Top




