 |
|
 |
It would be good if you could set the horizontal and vertical text aligment fot the items.
For instance, i want to use 32x32 icons as images in the list, so I set the ItemHeight to 34 (to get a little free space between icons). But the text is painted in the upper left corner, and it looks odd to say the least. I would prefer it if I could set a vertical alignment to "center"...
Otherwise, good work! I'll give you a 4. (If you fix the alignment, I COULD be persuaded to change it to 5 )
Why can't I be applicable like John? - Me, April 2011 ----- Beidh ceol, caint agus craic againn - Seán Bán Breathnach ----- Da mihi sis crustum Etruscum cum omnibus in eo! ----- Just because a thing is new don’t mean that it’s better - Will Rogers, September 4, 1932
|
|
|
|
 |
|
 |
You have the code - you can change the text alignment yourself - it's easy. The article is about exposing a custom object collection as a property. The image list was used only to make the article more attractive
|
|
|
|
 |
|
|
 |
|
 |
I promise you to include string alignment in next updates And even a property which will control it, because there are arabic languages, which aligned in completely different way.
|
|
|
|
 |
|
 |
Thanks...
Why can't I be applicable like John? - Me, April 2011 ----- Beidh ceol, caint agus craic againn - Seán Bán Breathnach ----- Da mihi sis crustum Etruscum cum omnibus in eo! ----- Just because a thing is new don’t mean that it’s better - Will Rogers, September 4, 1932
|
|
|
|
 |
|
 |
Hey Alex.
First off, nice project. Secondly, I've been passing this back and forth to everybody I can and can't get an answer: I'd like a component like yours but with the ability to display bigger pictures. I'm trying to find something like this for a twitter project, and in as good as yours is it doesn't seem to scale right. Maybe I'm doing wrong, but I think I need another control. Got any ideas?
|
|
|
|
 |
|
 |
Dear Alexander, I really liked your ImageListBox control. The only thing that I can't perform with it - is using the construction like this:
imageListBox.Items.Remove(imageListBox.SelectedItem);
It always writes when I try to delete an item that object reference is not set to an instance of an object.
Brustem
|
|
|
|
 |
|
 |
Dear Brustem,
The only exception I have encountered was "method not supported", because I did not implement the Remove method of the exposed collection, since it wasn't required for the sample.
You may implement something like this in the ImageListBoxItemCollection class:
public int IndexOf(object item)
{
for(int i = 0; i < this.Count; i++)
{
if(this[i] == item)
return i;
}
return -1;
}
public void Remove(ImageListBoxItem item)
{
int index = IndexOf(item);
if(index != -1)
{
owner.DoRemoveItem(index);
}
}
Alexander Yakovlev
You have connected at 14,400. Could you whistle a little louder to increase the connection speed?
|
|
|
|
 |
|
 |
Nice article mate.....
Just wonderful to create your own controls...
Thank you for sharing with us....
|
|
|
|
 |
|
 |
Hello,
the function FindString not working for imageListBox,
how resolve thats problem ?
Best Regards,
Sebastian.
|
|
|
|
 |
|
 |
Hello, sebaj,
You need to replace the ToString() method in the ImageListBoxItem.cs (for the Localizable version) with the following code:
public override string ToString()
{
if(this.DesignMode)
{
return "Item: {" + this.text + "}";
}
else
{
return this.text;
}
}
|
|
|
|
 |
|
 |
Hi. its a good work
I want to implement only collection property in mycontrol
the collection has two items one is DisplayValue 2nd is HiddenValue
But can't understand how to do it
plz let me tell how can i do this .....
Will be be very tankfull
|
|
|
|
 |
|
 |
good article - very good application
thanks
kfir
Kfir Arbel
|
|
|
|
 |
|
 |
Hi,
Thanks for the article, i found it very useful.
I am using a right to left language so i would like the control to display the image at the right side and the text to its left.
what would you modify in order to fix it?
I tried playing with the OnDrawItem method...but i didn't get the result i wanted.
any ideas?
"to code or not to code?" this is the question..
kolbis
|
|
|
|
 |
|
 |
I've made the ImageListBox display in a comboBox style dropdown. Upon dropping down the items, the image show perfectly. However, when I click one, the dropdown collapses and just the text shows (actually it's the ToString() override).
How can I show both the image and the proper text while in the collapsed view?
|
|
|
|
 |
|
 |
To my opinion, you've got to override the ComboBox.OnPaint method to display the information you want. I never tried my approach on comboboxes.
|
|
|
|
 |
|
 |
Hi!
I implemented something similar to your control. I have a control and I added to it an ImageList property. Then I added another property that represents the index within the ImageList. I want to be able to edit it like the ImageIndex in the Button class. So I added the TypeConverterAttribute and the EditorAttribute exactly as you did with the ImageListBoxItem. It works fine but I cannot see the small icons of the images inside the drop-down list. Do you have any idea what the problem might be?
TIA
Uriel
|
|
|
|
 |
|
 |
Alexander,
I have a play with your sample and I am impressed. It's the nearest example I've found to what I want to do which is make the TabPage Collection Editor use my own TabPage class.
I've worked out that the Collection Editor takes the "type" of object from the collection's Item method but I am having real problems sub-classing the TabControl.TabPageCollection class so that I can override it's indexer. Have you or anyone else done any work in this area?
|
|
|
|
 |
|
 |
Hi, I've tried all that you did. Am trying to build a custom menu with a collection of menuItem objects.
Now, the property editor does show up as you said, however, it does not wire up in the InitializeComponent() using an Add/AddRange method.. hence does not retain the value of the items in it.
My MenuItemConverter looks like this:
public class MenuItemConverter : ExpandableObjectConverter
{
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
if (destinationType == typeof(InstanceDescriptor))
{
return true;
}
return base.CanConvertTo(context, destinationType);
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if(destinationType == typeof(InstanceDescriptor))
{
ConstructorInfo ci = typeof(MenuPanelItem).GetConstructor(new Type[]{
typeof(string),
typeof(string),
typeof( MenuPanelItem.States )});
MenuPanelItem item = (MenuPanelItem)value;
return new InstanceDescriptor(ci, new object[]{item.Text, item.Name, item.ItemState}, true);
}
return base.ConvertTo(context, culture, value, destinationType);
}
Any help is greatly appriciated.
|
|
|
|
 |
|
 |
I just missed some code.. here it is:
public class ImageListBoxItemConverter : ExpandableObjectConverter
{
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
if (destinationType == typeof(InstanceDescriptor))
{
return true;
}
return base.CanConvertTo(context, destinationType);
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if(destinationType == typeof(InstanceDescriptor))
{
ConstructorInfo ci = typeof(ImageListBoxItem).GetConstructor(new Type[]{
typeof(string),
typeof(int)});
ImageListBoxItem item = (ImageListBoxItem)value;
return new InstanceDescriptor(ci, new object[]{item.Text, item.ImageIndex}, true);
}
return base.ConvertTo(context, culture, value, destinationType);
}
}
|
|
|
|
 |
|
 |
Since IList already inherits from ICollection and IEnumerable, was there any need to again inherit from these interfaces?
Best regards,
Paul.
Jesus Christ is LOVE! Please tell somebody.
|
|
|
|
 |
|
 |
Did you try not to implement ICollection and IEnumerable and did the control work as before?
|
|
|
|
 |
|
 |
Yes, I was initially trying to follow your guide then realized I was doing unnecessary work. I changed the based to only IList and got the same result.
Better still, the best way to implement collection is to extend the CollectionBase abstract class, which also implements the IList with some events to walk home with. In fact, all the IList and related interfaces are already implemented for you.
I finally changed my classes to inherit from the CollectionBase and got a more simplified code (no change in functionality).
You will get something similar to the following:
using System;
using System.ComponentModel;
using System.Collections;
namespace ClassLibrary1
{
public class Layers : System.Collections.CollectionBase
{
public Layers()
{
}
public Layer this[int index]
{
get
{
return (Layer)(List[index]);
}
set
{
List[index] = (Layer)value;
}
}
public int Add(Layer layer)
{
if (!Contains(layer))
return List.Add(layer);
return List.Count;
}
public bool Contains(Layer layer)
{
return List.Contains(layer);
}
public int IndexOf(Layer layer)
{
return List.IndexOf(layer);
}
public void Insert(int index, Layer layer)
{
List.Insert(index, layer);
}
public void Remove(Layer layer)
{
List.Remove(layer);
}
public void CopyTo(Layer[] array, int index)
{
List.CopyTo(array, index);
}
}
}
Best regards,
Paul.
Jesus Christ is LOVE! Please tell somebody.
|
|
|
|
 |
|
 |
But I don't see how your sample connects with my article. You have just simply implemented your own collection class (as in MSDN). The idea to inherit from CollectionBase in your case is good, but in my reply I meant the case of the control I have demonstrated. Please give a more sophisticated sample of a collection that may be edited in Windows Forms Designer.
Regards, Alexander.
|
|
|
|
 |
|
 |
I don't know what you mean by sophisticated sample. The code I posted was taken from a sample which is edited in Windows Forms Designer, the Layer is a control, so the Layers is a collection of the controls.
If you mean a modification of your code, then I can do that and post it to you tomorrow (it is midnight here in Japan!).
The layer/layers sample I built was just for trial, the actual application is big, with at least 15 assemblies.
Best regards,
Paul.
Jesus Christ is LOVE! Please tell somebody.
|
|
|
|
 |
Votes of 3 or less require a comment