none
Change Windows Desktop Background Color RRS feed

  • Question

  • I have seen multiple ways to change the windows image background, but is there a way to change the windows background to a color?

    I am looking to change the background between 2 colors based on something running or stopped but can not find a way to change color from Red to Green, only set images.

    Thursday, January 30, 2020 7:43 PM

Answers

  • Hi

    Here is some code from: HERE

     Private Declare Function SetSysColors Lib "user32.dll" (ByVal one As Integer, ByRef element As Integer, ByRef color As Integer) As Boolean
    
    
    Dim CD As New ColorDialog
    If CD.ShowDialog = DialogResult.OK Then
        Dim BackgroundColor As Integer = ColorTranslator.ToWin32(CD.Color)
        SetSysColors(1, 1, BackgroundColor)
    End If


    Regards Les, Livingston, Scotland

    • Marked as answer by Ryan Lashway Friday, January 31, 2020 2:52 PM
    Thursday, January 30, 2020 7:48 PM
  • Before you can see a color change you must tell the desktop not to use any wallpaper, for example -

    <DllImport("user32.dll", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Unicode, SetLastError:=True)>
    Public Shared Function SystemParametersInfo(ByVal uiAction As UInteger, ByVal uiParam As UInteger, ByVal pvParam As IntPtr, ByVal fWinIni As UInteger) As <MarshalAs(UnmanagedType.Bool)> Boolean
    End Function
    
    
    Dim iBuf As IntPtr = Marshal.StringToHGlobalUni(String.Empty)
    Dim ret As Boolean = SystemParametersInfo(&H14, 0, iBuf, 0)
    Marshal.FreeHGlobal(iBuf)
    
    

    • Marked as answer by Ryan Lashway Friday, January 31, 2020 2:52 PM
    Thursday, January 30, 2020 9:13 PM

All replies

  • Hi

    Here is some code from: HERE

     Private Declare Function SetSysColors Lib "user32.dll" (ByVal one As Integer, ByRef element As Integer, ByRef color As Integer) As Boolean
    
    
    Dim CD As New ColorDialog
    If CD.ShowDialog = DialogResult.OK Then
        Dim BackgroundColor As Integer = ColorTranslator.ToWin32(CD.Color)
        SetSysColors(1, 1, BackgroundColor)
    End If


    Regards Les, Livingston, Scotland

    • Marked as answer by Ryan Lashway Friday, January 31, 2020 2:52 PM
    Thursday, January 30, 2020 7:48 PM
  • Provided code works great, once question, do you know how to, from in VB.net, set the option on a windows 10 workstation to solid color instead of image?

    At first I didnt think it was working until I change the option to solid color manually, then it worked perfect.

    Thursday, January 30, 2020 8:58 PM
  • Before you can see a color change you must tell the desktop not to use any wallpaper, for example -

    <DllImport("user32.dll", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Unicode, SetLastError:=True)>
    Public Shared Function SystemParametersInfo(ByVal uiAction As UInteger, ByVal uiParam As UInteger, ByVal pvParam As IntPtr, ByVal fWinIni As UInteger) As <MarshalAs(UnmanagedType.Bool)> Boolean
    End Function
    
    
    Dim iBuf As IntPtr = Marshal.StringToHGlobalUni(String.Empty)
    Dim ret As Boolean = SystemParametersInfo(&H14, 0, iBuf, 0)
    Marshal.FreeHGlobal(iBuf)
    
    

    • Marked as answer by Ryan Lashway Friday, January 31, 2020 2:52 PM
    Thursday, January 30, 2020 9:13 PM