c# - 在 C# 中制作 Vista 风格的应用程序

标签 c# visual-studio windows-vista

我正在运行 windows vista 并希望获得看起来像常规 vista 程序的外观。是否有关于如何构建 Vista 风格应用程序的非常好的教程/文章?我还想学习如何使用 native 代码并将其转换为 C#,如 this 中所示。示例。

最佳答案

如果您使用的是 WinForms,相对实现它是很容易的,因为 WinForms 是基于 native Win32 控件的。许多控件都可以通过设置附加标志(通过向 native 控件发送消息)或使用 SetWindowTheme 来增强其呈现效果。 .这可以通过互操作来实现。

以一个简单的ListView为例。如果你想要一个资源管理器风格的 ListView ,你可以在 ListView 的公开句柄上使用 SetWindowTheme。我们使用互操作来访问 native SetWindowTheme() 函数,挂接 ListView 的窗口过程并在创建控件时应用主题:

static class NativeMethods
{
    public const int WM_CREATE = 0x1;

    [DllImport("uxtheme.dll", CharSet = CharSet.Unicode)]
    public extern static int SetWindowTheme(
        IntPtr hWnd, string pszSubAppName, string pszSubIdList);
}

class ListView : System.Windows.Forms.ListView
{
    protected override void WndProc(ref Message m)
    {
        if (m.Msg == NativeMethods.WM_CREATE) {
            NativeMethods.SetWindowTheme(this.Handle, "Explorer", null);
        }
        base.WndProc(ref m);
    }
}

默认 ListView 和增强版的区别: ListView difference http://img100.imageshack.us/img100/1027/62586064nt6.png

不幸的是,没有一种简单的方法适用于每个控件。有些控件甚至没有任何 WinForms 包装器。最近我偶然发现了一个不错的汇编in this CodeProject article值得一看。也可能有托管库将其打包。

关于c# - 在 C# 中制作 Vista 风格的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/555383/

相关文章:

windows - Windows Vista 上的 Sublime Text 2 文件关联

c# - 如何使用 C# 授予对文件夹和子文件夹中所有文件的读取权限?

c# - Virustotal 陷阱矿可疑.low.ml.score

c# - 在 WPF 中显示选定的 ComboBox 项

.net - 我想在 C# 构建期间运行脚本,但**仅当项目不是最新时**

java - Vista 的全局应用程序数据放在哪里?

c# - EntityFramework 5 Code First 多重继承映射 (TPC)

visual-studio - VS : "adding namespace will prevent the debug session from continuing" error中的ASP CORE调试

visual-studio - 如何在没有 Visual Studio 的情况下构建 Silverlight 4 应用程序?

java - 可执行 Jars 运行非常缓慢