NicoVB Posted December 27, 2002 Posted December 27, 2002 I have created a new component: an IconList Public Class IconList Inherits System.ComponentModel.Component Private mnIcons As Icons = New Icons() Public Property Icons() As Icons Get Return mnIcons End Get Set(ByVal Value As Icons) mnIcons = Value End Set End Property End Class Public Class Icons Inherits System.Collections.CollectionBase Public Sub Add(ByVal ico As Icon) List.Add(ico) End Sub Public Sub New() MyBase.New() End Sub Public Sub Remove(ByVal index As Integer) If index > Count - 1 Or index < 0 Then MsgBox("Index not valid!") Else List.RemoveAt(index) End If End Sub Public ReadOnly Property Item(ByVal index As Integer) As Icon Get Return CType(List.Item(index), Icon) End Get End Property End Class But when I try to add an item in the collection editor the editor gives this error message: Constructor on type System.Drawing.Icon not found Thanks in advance Quote Visit http://www.nico.gotdns.com Now ONLINE!
*Gurus* divil Posted December 28, 2002 *Gurus* Posted December 28, 2002 It is trying to create an instance of the Icon class to add to your collection, but it can't. I suggest you create your own class, with an Icon property, and make your collection a collection of that class. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
NicoVB Posted December 28, 2002 Author Posted December 28, 2002 So I have to build a new class clsIcon with Icon as a roperty in it. And then I have to write: Public Class Icons Inherits System.Collections.CollectionBase Public Sub Add(ByVal ico As Icon) List.Add(ico) End Sub Public Sub New() MyBase.New() End Sub Public Sub Remove(ByVal index As Integer) If index > Count - 1 Or index < 0 Then MsgBox("Index not valid!") Else List.RemoveAt(index) End If End Sub Public ReadOnly Property Item(ByVal index As Integer) As Icon Get Return CType(List.Item(index), Icon) End Get End Property End Class ???? Quote Visit http://www.nico.gotdns.com Now ONLINE!
NicoVB Posted December 28, 2002 Author Posted December 28, 2002 I have now done this changes, but there are other problems now. It's very strange... but there is NO CODE GENERATED in the 'Windows Form Designer generated code' region for me when I add a few IconAd elements. And when I set the property Icon from a IconAd element, it doesn't fill in that property. What is the problem here??? Quote Visit http://www.nico.gotdns.com Now ONLINE!
*Gurus* divil Posted December 28, 2002 *Gurus* Posted December 28, 2002 That new code you pasted isn't correct, I don't know if you've written more since then. Suggest you remove your Remove method for the time being, the designer doesn't need it. Also, there's no point declaring a sub new that just calls the base constructor, that's what it would do anyway. You have to make your collection accept and return items of your new class (IconAd was it) instead of icon. Getting the designer to generate code for your new class is a little tricky, but I wrote all about it in my tutorial in the tutor's corner entitled "Authoring Advanced Windows Forms Controls". Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
NicoVB Posted December 28, 2002 Author Posted December 28, 2002 Sorry, indeed my code was wrong. I've allready changed that code. Now i've removed the Sub New() also. And is it so difficult to do this? Is there no simplier way to build an IconList just the same like an ImageList???? I will try to read your tutorial. Quote Visit http://www.nico.gotdns.com Now ONLINE!
*Gurus* divil Posted December 28, 2002 *Gurus* Posted December 28, 2002 The ImageList has a custom collection editor dialog, which I have no experience in developing. If you want the designers to serialize your class, you have to write a custom type convertor for it, which I showed how to do in my tutorial. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
NicoVB Posted December 29, 2002 Author Posted December 29, 2002 Thank you for helping me a lot. Hopefuly my two iconcontrols will release soon in the code library!! Quote Visit http://www.nico.gotdns.com Now ONLINE!
NicoVB Posted December 29, 2002 Author Posted December 29, 2002 (edited) Another problem occured now. So the collection problem is OK. But I have for each IconAd element a Icon property. But if I want to fill in that Icon property, he just fills it as NOTHING. So why is that? (Also if I add a property 'temp' as String for example.) it creates this code: ---------------------------- IconAd1.Icon = Nothing IconAd2.Icon = Nothing Me.IconList1.Icons.Add(IconAd1) Me.IconList1.Icons.Add(IconAd2) Edited December 29, 2002 by NicoVB Quote Visit http://www.nico.gotdns.com Now ONLINE!
NicoVB Posted December 30, 2002 Author Posted December 30, 2002 Do you have a solution for this? Quote Visit http://www.nico.gotdns.com Now ONLINE!
*Gurus* divil Posted December 30, 2002 *Gurus* Posted December 30, 2002 I don't know how to tell the serializers to persist icons in the binary resource files, no. Try a google search for something like that. You want your class member to be serialized in the same manner as the .Icon property is for a form. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
NicoVB Posted December 30, 2002 Author Posted December 30, 2002 Sorry, but i made a very stupid mistake in the property statement. So you don't have to solve that problem BUT!!!! There is another LITTLE problem that has to be solved: ----------------------------------------------------------------------- When you set the property of ANOTHER control WITHOUT a collection on an icon. But you decides that you don't want to have an icon displayed on any sort of box. And you RIGHT click on the property like on the image property of a picturebox, you can see a menu with two options : RESET and DESCRIPTION. But when I right click on the icon property of my custom control, i can see only DESCRIPTION in that menu. This is a small problem. But it can be user-friendly that get rid of this problem. Thanks if you can solve this problem too. :D Quote Visit http://www.nico.gotdns.com Now ONLINE!
*Gurus* divil Posted December 30, 2002 *Gurus* Posted December 30, 2002 I didn't even know you did this, but I'd guess it would be by applying a DefaultValueAttribute to that member, passing Nothing. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
NicoVB Posted December 31, 2002 Author Posted December 31, 2002 I think I have found another solution. I read it in my book: 'Providing a Reset Method for a Control Property' ------------------------------------------------------------------ Public Sub ResetMyProperty() mnMyProperty = mnMyPropertyDefaultValue Me.Invalidate() It works. But many thanks for incredibily helping me and I now have written two new controls. Quote Visit http://www.nico.gotdns.com Now ONLINE!
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.