views:

478

answers:

3

I know I should generally avoid messing up with such system settings, but my application do already use nonstandard colors and I have no influence on that. I would like to be able to add standard .NET controls in some places, but their colors do not match. I would like to have a hack that would replace system colors for this one application. One more important thing to note is that it is a .NET application.

My (incomplete) ideas so far were:

  • To create a proxy User32.dll library with replaced GetSysColor, but it would be very tedious (731 functions to be redirected, 1 to be replaced) and I do not know how to force my application to use that particular copy.
  • To intercept somehow invocations to GetSysColors (unfortunatelly it is somewhere in the CLR I think).
  • To modify somehow .NET class SystemColors (in memory? is it possible?).

Do you have any idea, what is the best (and complete) way to achieve this?

+2  A: 

In my early days I developed a program that registered a global message hook to owner draw window borders - I could theme all windows. This should be possible for a single application, too. However, this is not a simple task.

Otherwise I don't think that this will be possible. How about using themable third party controls such as Krypton Toolkit?

Thorsten Dittmar
Actually I use some Divelements Controls, but they do not provide regular controls like buttons or scrollbars. I will check Krypton. Thank you for this suggestion.Would it be possible for you to send me this coloring program you are talking about? I would be thankful for any additional details.
Michal Czardybon
Sorry, can't send you the source for the tool - I must have written that around 1992 in Borland Pascal. The sources have been long lost...
Thorsten Dittmar
I have checked that - I do can intercept WM_PAINT event using system hooks, but it gives me nothing. I can do it simpler overriding OnPaint in my C# code. And I still cannot change colors in general. Maybe only the borders would be possible (knowing the client rectangle), but this is not enough.
Michal Czardybon
+4  A: 

I would like to be able to add standard .NET controls in some places, but their colors do not match. I would like to have a hack that would replace system colors for this one application.

That's like driving a nail with a sledgehammer.

Rather than mucking up colors within the system itself, what you can do is inherit a new control from each of the stock controls you want to use. So instead of a plain TextBox you inherit from the stock TextBox control to create your own ThemedTextBox. You setup this new control to use your app's color scheme by default, and because it is still a TextBox as far as the inheritance structure is concerned you can use it anywhere you'd use a normal textbox, including in the winforms designer.

Joel Coehoorn
Unfortunately in the .NET it is not possible to change colors in the inherited class. I would have to do all the drawing from scratch. And even that wouldn't be enough because of various visual styles possible (eg. XP vs Vista).
Michal Czardybon
Sure, you can change the colors. Just update the constructor for the inherited class to set the appropriate properties.
Joel Coehoorn
The problem is that in WinFoms there are no "appropriate properties". Control class has only ForeColor and BackColor, but this is not everything. For TextBox we can change only the back color, but for ScrollBar we can change nothing.
Michal Czardybon
A: 

My team decided to use this:
http://www.skin-soft.co.uk/
Works perfectly at the cost of 189$. We only had to add a script adding the skin-soft code only on our build machine. Local builds do not use custom colors, but in this way we only pay for a single license.

Michal Czardybon