Click here to Skip to main content
15,887,434 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have written a very simple user control in C#. It looks like a ComboBox and when you click the drop down it fires up either an OpenFileDialog or FolderBrowserDialog. When the user selects a file or folder its path is shown in the text portion of my control.
The control just has a button docked to the right and a text box docked to fill the rest of the control.
It has an ImageList with several images associated with the Button. Normally when you choose an image in the IDE you get a drop down in the Properties Window and can see the images which makes it easy to choose one.
I would like that drop down available in my user control if possible. I can expose all of the properties of the Button but can't find a way to expose just the ImageIndex with the nice drop down.
Can anybody give me a steer on how to achieve this please?

What I have tried:

I have investigate using "TypeConvertor" and "Editor" in the properties but every time I think I am getting close I discover I'm not!
Posted
Updated 12-May-19 4:20am
Comments
[no name] 12-May-19 6:25am    
Can't tell if you're trying to create an "image list", or have an "image list" but cannot figure out the "index" ... which is not part of an "image list" ... Guess it's Windows Forms and not WPF or UWP ...

OK, solved!
Firstly the User Control must have its own ImageList property so I added that with a 'get' accessor only. Then the property became:

C#
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[Browsable(true), Description("The Image Index for the button"), DefaultValue(0)]
[TypeConverter(typeof(ImageIndexConverter))]
[Editor("System.Windows.Forms.Design.ImageIndexEditor", typeof(UITypeEditor))]
[RelatedImageList("ImageList")]
public int ImageIndex
{
	get { return btnPick.ImageIndex; }
	set { btnPick.ImageIndex = value; }
}


QED!
 
Share this answer
 
v2
Thanks Gerry. I realised as soon as I pressed the button I had missed some important information :-(
I have a base control, looks like a ComboBox and of course I can access all the properties in that. The Button it contains has an associated ImageList.
I then have a File/Folder picker derived from that base control and want to access the ImageIndex of the Button in the derived control using the same editor that Button itself uses. I have made some progress:

[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
		[Browsable(true), Description("The Image Index for the button"), DefaultValue(0)]
		[System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.ImageIndexConverter))]		
		public int ImageIndex
		{
			get { return btnPick.ImageIndex; }
			set { btnPick.ImageIndex = value; }
		}


This does provide a drop down picker in the IDE properties window but it's empty!
I think I need an [Editor...] attribute but don't know which one is appropriate.
 
Share this answer
 
Comments
phil.o 12-May-19 6:41am    
Please do not bring more information to your question by providing a solution :)
You should rather click on the green "Improve question" widget which appears at the bottom of your question when you hover it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900