Disabling visual styles for a specific form/control

Hello!

Is it possible to disable XP themes for a specific form or control in .NET Framework 1.1

I am developing a custom control and I have no control over the user (if he calls Application.EnableVisualStyles() or not) but I'd still like to be sure that my control is displayed properly.

Best regards!
Marcin


Answer this question

Disabling visual styles for a specific form/control

  • aish

    Yes, as for controls that support the FlatStyle property, you are right.

    However, some GUI controls have problems with XP themes (e.g. TabPage) and do not allow me to alter their behaviour and look easily.

    Best regards!
    Marcin


  • keroed1

    what do you mean by "no control over the user"

    I think as long as you did not set the flatstyle of the control(like button, etc) to system, the visualstyles will not take effect.

  • DMG

    With a little Interop it's no problem. VB example follows:



    Friend Declare Unicode Function SetWindowTheme Lib "UxTheme.dll" _
        (
    ByVal hwnd As IntPtr, _
        ByVal pszSubAppName As String, _
        ByVal pszSubIdList As String) As Integer

    Private Sub EnableVisualStyles(ByVal control As Control)
        If OSFeature.Feature.IsPresent(OSFeature.Themes) Then
            SetWindowTheme(control.Handle,
    Nothing, Nothing)
        End If
    End Sub

    Private Sub DisableVisualStyles(ByVal control As Control)
        If OSFeature.Feature.IsPresent(OSFeature.Themes) Then
            SetWindowTheme(control.Handle, "", "")
        End If
    End Sub


     

  • Disabling visual styles for a specific form/control