Windows在某些情况(系统文件损坏、注册表错误、驱动不兼容等)下,桌面图标间距变得超大,占满整个桌面。
整理下,C#按如下方式修复
1 using var windowMetrics = Registry.CurrentUser.CreateSubKey(@"Control Panel\Desktop\WindowMetrics");
2 if (windowMetrics == null)
3 {
4 return;
5 }
6 //默认情况下,水平和垂直间距的值都是-1125。范围是-480到-2730之间的任何整数
7 //修复后,windows重启生效
8 if (!(windowMetrics.GetValue("IconSpacing") is string iconSpacing && iconSpacing == DefaultIconSpacing))
9 {
10 windowMetrics.SetValue("IconSpacing", DefaultIconSpacing, RegistryValueKind.String);
11 }
12 if (!(windowMetrics.GetValue("IconVerticalSpacing") is string iconVerticalSpacing && iconVerticalSpacing == DefaultIconSpacing))
13 {
14 windowMetrics.SetValue("IconVerticalSpacing", DefaultIconSpacing, RegistryValueKind.String);
15 }
默认的间距值:
private const string DefaultIconSpacing = "-1125";
作者:唐宋元明清2188