1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

WPF タイトルバーの色を変える

1
Posted at
  • WIN11のみ
  • ウィンドウがアクティブの時に青色、非アクティブ時はグレーアウトされます
    RGB値を可変して下さい
  • WIN95,XPはアクティブウィンドウは勝手に青色になったがWIN11はアクティブでもグレーのままで分かりづらい
  • 自身が開発している DetailAllData(DADシステム)で採用
  • 元はOPEN AIの回答です

SRC

using System;
using System.Runtime.InteropServices;
using System.Windows.Interop;
// TITLE COLOR
private const int DWMWA_CAPTION_COLOR = 35;

[DllImport("dwmapi.dll")]
private static extern int DwmSetWindowAttribute(IntPtr hwnd,int dwAttribute,ref int pvAttribute,int cbAttribute);
private void SetTitleBarColor(int color){
    IntPtr hwnd = new WindowInteropHelper(this).Handle;
    DwmSetWindowAttribute( hwnd, DWMWA_CAPTION_COLOR, ref color, Marshal.SizeOf<int>());
}

private void Window_Activated(object sender, EventArgs e)        {
    // 青
    SetTitleBarColor(0x00FF0000);
}

private void Window_Deactivated(object sender, EventArgs e)        {
    // グレー
    SetTitleBarColor(0x00A0A0A0);
}
// public MainWindow() の中に追記 無くても可かも
SetTitleBarColor(0x00FF0000);

XAML 頭の <Window 内に追記

Activated="Window_Activated" Deactivated="Window_Deactivated"
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?