Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Change Windows Forms Title Bar color
Message
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Divers
Thread ID:
00789220
Message ID:
00789250
Vues:
29
Hi Don,

There is not a easy way to set a the color of a single Window's title bar. You only can set the system color setting by via the SetSysColors API. You can work around the issue in this way:

1. In the Activated event of the form store the Windows setting of the title bar and set it to your color
2. In the Deactivate event restore the Windows setting

There is a sample code of it:
Imports System.Runtime.InteropServices
<DllImport("user32.dll")> _
Private Shared Function GetSysColor(ByVal nIndex As Int32) As Int32
End Function

<DllImport("user32.dll")> _
Private Shared Function SetSysColors(ByVal cElements As Integer, ByVal lpaElements() As Int32, ByVal lpaRgbValues() As Int32) As [Boolean]
End Function

Private Const COLOR_ACTIVECAPTION As Integer = 2

Private oldColor As Integer

Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
    oldColor = GetSysColor(COLOR_ACTIVECAPTION)

    Dim element() As Integer = {COLOR_ACTIVECAPTION}
    Dim rgb() As Integer = {Color.White.ToArgb() And &HFFFFFF}
    Dim b As Boolean = SetSysColors(1, element, rgb)
End Sub 'Form1_Activated

Private Sub Form1_Deactivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Deactivate
    Dim element() As Integer = {COLOR_ACTIVECAPTION}
    Dim rgb() As Integer = {oldColor}
    Dim b As Boolean = SetSysColors(1, element, rgb)
End Sub 'Form1_Deactivate
>How do I change the color of the Title Bar in Windows Forms (VB.Net)? I need to set it to green and have been unable to find a reference so far.
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform