Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
What I am trying to do is to add a custom tab with custom colors into the ColorUI class of ColorEditor class which appears into the PropertyGrid of controls.

Something like this ( just a fake image made in Photoshop ).

What I have tried:

I understand that in some way I have to create my own ColorEditor class and override the ColorUI class which is nested inside original ColorEditor class but I don't know which method I have to override so to add this extra Tab etc.

Any idea?

Thank you for your time!!!
Posted
Updated 12-Dec-22 2:04am
v3

I have found something (perhaps) interesting for you :
WinForms ColorEditor Displayed Modeless[^]
Maybe it helps you to create you own ColorEditor ...
 
Share this answer
 
Comments
Simos Sigma 12-Dec-22 9:29am    
Hello Ralf!!!

Well based on Reflection approach we were talking yesterday, I managed to add the extra Tab into my custom ColorEditor.
Here[^] is an incomplete example.

I have to change it so to list my custom colors instead of Common Colors.
I have to make it draw all this into MyColors_ListBox.
I have to make it pass the value into public override object EditValue(ITypeDescriptorContext context, System.IServiceProvider provider, object value).
And make properties list to close after selection.

Now I am examining the project from the link you gave me (looks really promising) to see if this can help me to fill the "gaps". Else I'll start over based 100% on this project!!! :)
Ralf Meier 12-Dec-22 11:17am    
Thanks for the Sample - I will take later a deeper look on it ...
The posted Solution I found (on CP) while looking for a complete different approach ...
Simos Sigma 13-Dec-22 10:25am    
Ralf I got a good answer[^] in Stackoverflow!!!
Ralf Meier 13-Dec-22 11:54am    
OK ... very good ... that seems to be exactly (or nearly) what you have asked for ...
Since I am a kind of collector it is very interesting for me - who knows when I need something like that by myself ...
Thanks for your Reply :)
Simos Sigma 14-Dec-22 4:37am    
You are welcome Ralf!!! It's my pleasure!!! :)
It sounds like you want to create a custom color editor class that extends the existing ColorEditor class. To add a new tab with custom colors, you will need to override the ColorUI class, which is nested inside the original ColorEditor class.

To do this, you can create a new class that extends the ColorEditor class and overrides the ColorUI class. Here is an example of how you might do this:

public class CustomColorEditor : ColorEditor
{
    protected override void ColorUI(Color value)
    {
        // Add your custom tab with custom colors here
    }
}



Once you have created your custom color editor class, you can use it in your WinForms application by setting the PropertyEditor property of your PropertyGrid control to your custom color editor class.

Here is an example of how you might do this:

// Create a new instance of your custom color editor class
CustomColorEditor customColorEditor = new CustomColorEditor();

// Set the PropertyEditor property of your PropertyGrid control to your custom color editor
propertyGrid.PropertyEditor = customColorEditor;


I hope this helps!
 
Share this answer
 
Comments
Simos Sigma 11-Dec-22 5:00am    
Thank you very much for your answer!!!

I tried your solution but I get this error:
CS0115 'CustomColorEditor.ColorUI(Color)': no suitable method found to override.

I had also placed the same question in Stackoverflow and I got this answer.
Ralf Meier 11-Dec-22 6:35am    
Basicly I can imagine that the Solution from Mike is working - but there is a lot of knowledge neccessary to do this.
In the past I often modified the windows-delivered Editors but mostly to exclude given controls or functions - but I suppose that the other way round is also possible. For this you need to know the content of the UI - that means : what is the Name of the Tabcontrol and where is it located. Now you can perhaps add another Tabpage to it with the content you like to have. The functions of your new Tabpage must deliver the selected value to the Return-Parameter from the original UI - for this you need to know how it is done. I think that this is the most problematicly part (and I have no idea how it could be done).
If you want to have this special function ... why don`t you create you own ColorEditor which works like you want to have ...?
Simos Sigma 11-Dec-22 6:42am    
As I wrote to Mike, I found this into a Stackoverflow question which is a custom color editor (as you proposed) and says that we can also add a custom Tab with custom colors and it's close to Mikes's approach. But seeing the code, again, I can't understand where should I add my custom Tab code!!!
Ralf Meier 11-Dec-22 6:54am    
As I wrote before :
You must use Reflection. Each Control has a Controls-Collection which holds all Sub-Control inside it (if there are some). Now what you have to do is : iterate through this collection and find the Name (and by this also) the Reference from the Tabcontrol. But perhaps (that could also be possible) the control is the TabControl (that means derives from it).
If you have the TabControls Reference you can add a new TabPage to it.
How familiar are you with doing something like this ?
Simos Sigma 11-Dec-22 7:12am    
I think I understand 100% what you are writing... The point is, in practice, what can I dο? :)

So, using Reflection I have to find the TabControl inside ColorUI and then add my custom TabPage etc. I have also open the ColorEditor.cs decompiled, which contains the ColorUI and I am trying to find names of fields and controls which I'll use with Reflection. Am I on track?
 
Share this answer
 
v3
Comments
Simos Sigma 10-Dec-22 8:31am    
Sorry I wrote "ColorDialog", I meant "ColorEditor"!!!
See ColorDialog Class (System.Windows.Forms) | Microsoft Learn[^] for information on customising this dialog.
 
Share this answer
 
Comments
Simos Sigma 10-Dec-22 8:31am    
Sorry I wrote "ColorDialog", I meant "ColorEditor"!!!
Richard MacCutchan 10-Dec-22 8:38am    
The same answer, check the documentation for that class, and especially its parent at UITypeEditor Class (System.Drawing.Design) | Microsoft Learn[^].

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