Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Visit http://www.nico.gotdns.com

 

Now ONLINE!

Posted

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

 

 

????

Visit http://www.nico.gotdns.com

 

Now ONLINE!

Posted

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???

Visit http://www.nico.gotdns.com

 

Now ONLINE!

  • *Gurus*
Posted

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".

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted

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.

Visit http://www.nico.gotdns.com

 

Now ONLINE!

  • *Gurus*
Posted

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.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted (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 by NicoVB

Visit http://www.nico.gotdns.com

 

Now ONLINE!

  • *Gurus*
Posted

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.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted

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

Visit http://www.nico.gotdns.com

 

Now ONLINE!

Posted

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.

Visit http://www.nico.gotdns.com

 

Now ONLINE!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...