tags:

views:

57

answers:

1

It is possible to use the XP styles in Vista/Win7? If yes, is it possible to do it for a single control.

I know I can turn off visual styles one control at a time using SetWindowTheme(). I know it is possible to turn off visual styles for the whole win forms app by removing the EnableVisualStyles call.

The reason I ask is because in the application this would be used it a control in a error state has it's backcolor turned red. This does not work for ComboBoxes when the application is running under Vista/Win7. Changing the back color only changes for the drop down list not the actual control.

I have also looked into getting the BackColor to change the combobox color like it does in XP and when visual styles are off but have found no way to easily do that either.

And yes this would be easily solved in WPF... /cry. :)

+1  A: 

Well, you already know how to do it.

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

class MyComboBox : ComboBox {
    protected override void OnHandleCreated(EventArgs e) {
        base.OnHandleCreated(e);
        SetWindowTheme(this.Handle, "", "");
    }
    [DllImport("uxtheme.dll")]
    private static extern int SetWindowTheme(IntPtr hWnd, string appname, string idlist);
}

No matter what you do, it will look starkly off to a user that's used to seeing her UI designs having visual styles turned on. And tick off one that has visual impairments, something that can get you sued in the USA. Windows Forms already has a very good way to indicate errors, the ErrorProvider was designed to do that.

Hans Passant
Thank you for answering. I pretty much assumed the answer to this question but need to weight my options. I have a few more since it is an internal application.
Tony
I am accepting this as the answer. Even if there is a way to do what I asked in my question, it is not correct for a number of reasons and will cause more problems down the road. Like I said before, just weighing the options. Even the bad ideas need to be looked at once in a while. ;)
Tony