change background color or image in windows form application in the taskbar...
You can use ITaskbarList3.SetOverlayIcon to set a colored icon in the Taskbar Button, like in the MS SDK sample :
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Thanks for reading. We have a VB.NET windows form application running .NET 4.8 Framework. Users often run multiple instances of the application. When this occurs, all of the same colored minimized windows in the taskbar make it difficult for the user to distinguish the different instances. I would like to implement a background color change based on the users Process ID (System.Diagnostics.Process.GetCurrentProcess). For instance, if the user had 3 instances of the application running with 2 forms open apiece then there would be 6 windows in the taskbar of the same color and/or text. I would like to differentiate between those 3 instances if possible. Thanks for the help.
change background color or image in windows form application in the taskbar...
You can use ITaskbarList3.SetOverlayIcon to set a colored icon in the Taskbar Button, like in the MS SDK sample :
Basic logic would go into MyApplication class which is created from project properties, Application tab, View Application events
button.
Something like this which as coded is limited to colors/open instances of an application.
Imports Microsoft.VisualBasic.ApplicationServices
Namespace My
Partial Friend Class MyApplication
Public backColorDictionary As Dictionary(Of Integer, Color) =
New Dictionary(Of Integer, Color) From
{
{1, Color.Red},
{2, Color.Green},
{3, Color.Blue},
{4, Color.DarkOrange}
}
Private _color As Color
''' <summary>
''' Form background color
''' </summary>
''' <returns></returns>
Public ReadOnly Property BackColor() As Color
Get
Return _color
End Get
End Property
''' <summary>
''' Logic to determine background color to use or a default if more instance
''' of the application open than colors in <see cref="backColorDictionary"/>
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
Private Sub MyApplication_Startup(sender As Object, e As StartupEventArgs) Handles Me.Startup
Dim currentProcess = Process.GetCurrentProcess().ProcessName
Dim counter = Process.GetProcessesByName(currentProcess).Length
If counter <= backColorDictionary.Count Then
_color = backColorDictionary(counter) '
Else
_color = Color.White
End If
End Sub
End Class
End Namespace
Then in a form load event
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
BackColor = My.Application.BackColor
Here we get over 100 colors
Imports System.Reflection
Imports Microsoft.VisualBasic.ApplicationServices
Namespace My
Partial Friend Class MyApplication
Public backColorDictionary As Dictionary(Of Integer, Color) = CreateColorsDictionary()
Public Shared Function ColorStructToList() As List(Of Color)
Return GetType(Color).GetProperties(
BindingFlags.Static Or
BindingFlags.DeclaredOnly Or
BindingFlags.Public).Select(
Function(c)
Return CType(c.GetValue(Nothing, Nothing), Color)
End Function).ToList()
End Function
Private Function CreateColorsDictionary() As Dictionary(Of Integer, Color)
Dim colors = ColorStructToList()
Dim results = colors.Select(Function(item, index) New With
{
.Index = index + 1,
.Color = item
})
Dim Dictionary = New Dictionary(Of Integer, Color)
For Each anonymous In results
If anonymous.Color = Color.Transparent Then
Dictionary.Add(anonymous.Index, Color.White)
Else
Dictionary.Add(anonymous.Index, anonymous.Color)
End If
Next
Return Dictionary
End Function
Private _color As Color
''' <summary>
''' Form background color
''' </summary>
''' <returns></returns>
Public ReadOnly Property BackColor() As Color
Get
Return _color
End Get
End Property
''' <summary>
''' Logic to determine background color to use or a default if more instance
''' of the application open than colors in <see cref="backColorDictionary"/>
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
Private Sub MyApplication_Startup(sender As Object, e As StartupEventArgs) Handles Me.Startup
Dim currentProcess = Process.GetCurrentProcess().ProcessName
Dim counter = Process.GetProcessesByName(currentProcess).Length
If counter <= backColorDictionary.Count Then
_color = backColorDictionary(counter) '
Else
_color = Color.White
End If
End Sub
End Class
End Namespace
Opening three instances gets
very helpful both Castorix31 and Karen. Thanks!