2009-07-18 12 views
0

次のコードは、ウィンドウの背景に使用されているシステムカラーを置き換えるものです。あなたはP/SetSysColor()API関数を呼び出してそれを変更します。私は私に示唆された次のコードを使用していますが、残念ながらボタンをクリックしても何も起こりません!Windowsの背景のシステムカラーを置き換えます。

Imports System 
Imports System.Drawing 
Imports System.Windows.Forms 
Imports System.Runtime.InteropServices 

Namespace WindowsFormsApplication1 
    Partial Public Class Form1 
     Inherits Form 
     Private oldcolor As Integer 
     Public Sub New() 
      InitializeComponent() 
      oldcolor = GetSysColor(COLOR_WINDOW) 
      AddHandler Me.FormClosed, AddressOf Form1_FormClosed 
      AddHandler Me.button1.Click, AddressOf button1_Click 
     End Sub 

     Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As FormClosedEventArgs) Handles MyBase.FormClosed 
      Dim element As Integer = COLOR_WINDOW 
      SetSysColors(1, element, oldcolor) 
     End Sub 

     Private Function Color2COLORREF(ByVal color As Color) As Integer 
      Return color.R Or (color.G << 8) Or (color.B << &H10) 
     End Function 

     Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click 
      Dim element As Integer = COLOR_WINDOW 
      Dim colorref As Integer = Color2COLORREF(Color.NavajoWhite) 
      SetSysColors(1, element, colorref) 
     End Sub 

     Private Const COLOR_WINDOW As Integer = 5 
     <DllImport("user32.dll")> _ 
     Private Shared Function SetSysColors(ByVal one As Integer, ByRef element As Integer, ByRef color As Integer) As Boolean 
     End Function 
     <DllImport("user32.dll")> _ 
     Private Shared Function GetSysColor(ByVal element As Integer) As Integer 
     End Function 

     Friend WithEvents Button1 As System.Windows.Forms.Button 
     Private Sub InitializeComponent() 
      Me.Button1 = New System.Windows.Forms.Button 
      Me.SuspendLayout() 
      ' 
      'Button1 
      ' 
      Me.Button1.Location = New System.Drawing.Point(71, 61) 
      Me.Button1.Name = "Button1" 
      Me.Button1.Size = New System.Drawing.Size(153, 126) 
      Me.Button1.TabIndex = 0 
      Me.Button1.Text = "Button1" 
      Me.Button1.UseVisualStyleBackColor = True 
      ' 
      'Form1 
      ' 
      Me.ClientSize = New System.Drawing.Size(284, 264) 
      Me.Controls.Add(Me.Button1) 
      Me.Name = "Form1" 
      Me.ResumeLayout(False) 

     End Sub 




    End Class 
End Namespace 

答えて

2

これは機能します。変更している色は、たとえばリストボックスで使用される背景色です。したがって、フォームにリストボックスを追加し、ボタンをクリックして、魔法を見ます:o)フォームの背景色を設定する場合は、別の要素値を使用する必要があります。私はa post with an enumeration of valid valuesが見つかりました:(あなたのプログラムが実行されている限り)

Public Enum SystemColor As Integer 
    ScrollBar = 0 'The Scrollbar colour ' 
    BackGround = 1 'Colour of the background with no wallpaper ' 
    ActiveCaption = 2 'Caption of Active Window ' 
    InactiveCaption = 3 'Caption of Inactive window ' 
    Menu = 4 'Menu ' 
    Window = 5 'Windows background ' 
    WindowFrame = 6 'Window frame ' 
    MenuText = 7 'Window Text ' 
    WindowText = 8 '3D dark shadow (Win95) ' 
    CaptionText = 9 'Text in window caption ' 
    ActiveBorder = 10 'Border of active window ' 
    InactiveBorder = 11 'Border of inactive window ' 
    AppWorkspace = 12 'Background of MDI desktop ' 
    Highlight = 13 'Selected item background ' 
    HighlightText = 14 'Selected menu item ' 
    BtnFace = 15 'Button ' 
    BtnShadow = 16 '3D shading of button ' 
    GrayText = 17 'Grey text, of zero if dithering is used. ' 
    BtnText = 18 'Button text ' 
    InactiveCaptionText = 19 'Text of inactive window ' 
    BtnHightList = 20 '3D highlight of button ' 
    SecondActiveCatpion = 27 'Win98 only: 2nd active window color ' 
    SecondInactiveCaption = 28 'Win98 only: 2nd inactive window color ' 
End Enum 

しかし、これは、同様のプログラムを実行しているすべての背景色を変更します。すなわち、例えばとのリンクについては...行うには非常にいいことだと

更新

を私に当たらない:これは、アプリケーションの実行中に、あなたのコードは、私のWordインスタンスにやったことです:

私の作品

alt text

アップデート2

全コード:

Imports System 
Imports System.Drawing 
Imports System.Windows.Forms 
Imports System.Runtime.InteropServices 

Public Class Form1 
    Inherits Form 
    Private oldcolor As Integer 
    Public Sub New() 
     InitializeComponent() 
     oldcolor = GetSysColor(SystemColor.Window) 
     AddHandler Me.FormClosed, AddressOf Form1_FormClosed 
     AddHandler Me.Button1.Click, AddressOf button1_Click 
    End Sub 

    Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As FormClosedEventArgs) Handles MyBase.FormClosed 
     SetSysColors(1, SystemColor.Window, oldcolor) 
    End Sub 

    Private Function Color2COLORREF(ByVal color As Color) As Integer 
     Return color.R Or (color.G << 8) Or (color.B << &H10) 
    End Function 

    Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click 
     SetSysColors(1, SystemColor.Window, Color2COLORREF(Color.NavajoWhite)) 
    End Sub 

    <DllImport("user32.dll")> _ 
    Private Shared Function SetSysColors(ByVal one As Integer, ByRef element As Integer, ByRef color As Integer) As Boolean 
    End Function 
    <DllImport("user32.dll")> _ 
    Private Shared Function GetSysColor(ByVal element As Integer) As Integer 
    End Function 

    Friend WithEvents Button1 As System.Windows.Forms.Button 
    Private Sub InitializeComponent() 
     Me.Button1 = New System.Windows.Forms.Button 
     Me.SuspendLayout() 
     ' 
     'Button1 
     ' 
     Me.Button1.Location = New System.Drawing.Point(21, 50) 
     Me.Button1.Name = "Button1" 
     Me.Button1.Size = New System.Drawing.Size(153, 126) 
     Me.Button1.TabIndex = 0 
     Me.Button1.Text = "Button1" 
     Me.Button1.UseVisualStyleBackColor = True 
     ' 
     'Form1 
     ' 
     Me.BackColor = System.Drawing.SystemColors.Window 
     Me.ClientSize = New System.Drawing.Size(284, 264) 
     Me.Controls.Add(Me.Button1) 
     Me.Name = "Form1" 
     Me.ResumeLayout(False) 
     Me.PerformLayout() 
    End Sub 
End Class 

Public Enum SystemColor As Integer 
    ScrollBar = 0 'The Scrollbar colour ' 
    BackGround = 1 'Colour of the background with no wallpaper ' 
    ActiveCaption = 2 'Caption of Active Window ' 
    InactiveCaption = 3 'Caption of Inactive window ' 
    Menu = 4 'Menu ' 
    Window = 5 'Windows background ' 
    WindowFrame = 6 'Window frame ' 
    MenuText = 7 'Window Text ' 
    WindowText = 8 '3D dark shadow (Win95) ' 
    CaptionText = 9 'Text in window caption ' 
    ActiveBorder = 10 'Border of active window ' 
    InactiveBorder = 11 'Border of inactive window ' 
    AppWorkspace = 12 'Background of MDI desktop ' 
    Highlight = 13 'Selected item background ' 
    HighlightText = 14 'Selected menu item ' 
    BtnFace = 15 'Button ' 
    BtnShadow = 16 '3D shading of button ' 
    GrayText = 17 'Grey text, of zero if dithering is used. ' 
    BtnText = 18 'Button text ' 
    InactiveCaptionText = 19 'Text of inactive window ' 
    BtnHightList = 20 '3D highlight of button ' 
    SecondActiveCatpion = 27 'Win98 only: 2nd active window color ' 
    SecondInactiveCaption = 28 'Win98 only: 2nd inactive window color ' 
End Enum 
+0

私はそれがここのように動作します:http://www.thomson-software-solutions.com/html/screen_tinter.html –

+0

非常に非常に非常に非常にありがとう。すべてあなたに最高 –

+0

どのようにあなたのコメントを削除してきた? –