7
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

WinForms の TreeView をエクスプローラースタイルにする方法

7
Last updated at Posted at 2022-01-02

WinForms の TreeView をエクスプローラースタイルにする方法

通常のツリービュー

  • 非アクティブ時に選択状態が見え難い

tv_normal.png

エクスプローラースタイル

  • 展開記号が矢印
  • 非アクティブ時も選択状態が見え易い

tv_explorer.png

サンプルコード

using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;

static class NativeMethods
{
	[DllImport("uxtheme.dll", ExactSpelling = true, CharSet = CharSet.Unicode)]
	public static extern int SetWindowTheme(IntPtr hwnd, string pszSubAppName, string pszSubIdList);
}

static void InitializeTreeView(TreeView tv)
{
	tv.FullRowSelect = true;
	tv.HideSelection = false;
	tv.ShowLines = false;

	NativeMethods.SetWindowTheme(tv.Handle, "explorer", null);
}
7
11
4

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
7
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?