【发布时间】:2011-11-28 16:08:03
【问题描述】:
我正在开发一个使用视觉样式的程序。 Main 方法如下所示:
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form());
}
该程序还可以作为另一个应用程序的插件使用,在这种情况下,它是通过 COM 启动的。问题是调用应用程序(COM 客户端)没有调用 EnableVisualStyles,它不在我的控制范围内。在这种情况下,程序启动如下:
public static void StartAsPlugin() {
Application.EnableVisualStyles();
Form form = new Form();
form.ShowDialog();
}
当程序作为插件启动时,进度条和组合框不会以与程序正常启动时相同的样式呈现,而按钮、复选框和单选按钮都可以。 有没有办法强制视觉风格?我试过清单,但没有运气! 这是我尝试过的清单:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
version="1.0.0.0"
processorArchitecture="*"
name="RealApp"
type="win32"
/>
<description>Your application description here.</description>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
</assembly>
我认为清单已正确嵌入,因为 ildasm 在清单部分显示以下内容:
.mresource public RealApp.RealApp.exe.manifest
{
// Offset: 0x000004F0 Length: 0x0000029B
}
谢谢, 斯泰尼奥
【问题讨论】:
-
如果没记错的话,清单应该可以解决问题。请在您的帖子中附上您的清单,以便我们确认您的内容是否正确。
-
我已将清单添加到帖子中。感谢您的帮助。
-
你任由调用的 EXE 摆布,在创建任何窗口之前需要激活视觉样式。清单不能工作,它需要是调用 EXE 的清单。
-
它没有,.NET 已经使用了。
-
如果它真的那么重要,您可能需要使用原生 UxTheme API msdn.microsoft.com/en-us/library/windows/desktop/… 绘制控件
标签: c# .net winforms plugins com