是基本的.NET Windows窗体控件机Win32控制?窗体、控件、基本、Windows

2023-09-03 17:06:36 作者:沉囵怹菂鎂

你的.NET Windows窗体应用程序使用相当于本地Win32控制基本控制,如文本框和按钮? WPF是母语为非但Windows窗体的外观和感觉非常原始。在Button控件上的动画,看起来就像一个Win32按钮。

Do .NET Windows Forms applications use the equivalent native Win32 controls for basic controls such as Textbox and Button? WPF is non-native but Windows Forms looks and feels very native. The animations on the Button control look exactly like a Win32 button.

推荐答案

是的,他们是和hellip;有一些例外

Yes, they are…with a couple of exceptions.

有些东西在WinForms的是定制绘制。他们使用本机的控制,但他们打开所有者描述,并在C#code在内部处理一些图形逻辑。这样做的好处是它允许像按钮有一个背景色属性,支持用户自定义的颜色,而不是标准的系统颜色。通常情况下,这应该是避免(至少在我看来),因为不仅效果丑陋的,有可能是用户选择他们做的配色方案有原因的。但是图形设计师往往认为他们比用户更好,所以选项存在。

Some things in WinForms are custom drawn. They use the native control, but they turn on owner-draw and handle some of the drawing logic internally in C# code. The advantage of this is it allows things like buttons to have a BackColor property that supports a user-defined color instead of the standard system color. Generally, this should be avoided (at least in my opinion) because not only is the effect ugly, there's probably a reason the user chose the color scheme they did. But graphic designers often think they know better than users, so the option exists.

控制可以实现像这样经常暴露的FlatStyle 属性,它允许您更改他们是如何绘制的(例如,ButtonBase.FlatStyle)随着 FlatStyle.Standard ,.NET框架不正常的所有​​者绘制,即使你没有定制任何控件的属性不寻常的设置。用 FlatStyle.System 的控制是通过Win32的直接呈现,没有任何所有者绘制或其他覆盖。

Controls that are implemented like this often expose a FlatStyle property that allows you to change how they are drawn (for example, ButtonBase.FlatStyle) . With FlatStyle.Standard, the .NET Framework does its normal owner drawing, even if you haven't customized any of the control's properties with unusual settings. With FlatStyle.System, the control is rendered directly by Win32 without any owner-draw or other overrides.

您可以告诉按钮上pretty的区别很容易。当设置为 FlatStyle.System ,按钮上的蓝色悬停效果逐渐淡入和淡出。当设置为 FlatStyle.Standard ,蓝色光芒突然出现和消失。关闭,但并不完全一样。组合框做同样的事情(至少在他们的DropDownStyle属性设置为 ComboBoxStyle.DropDownList )。

You can tell the difference on buttons pretty easily. When set to FlatStyle.System, the blue hover effect on buttons gradually fades in and out. When set to FlatStyle.Standard, the blue glow suddenly appears and disappears. Close, but not quite the same. Combo boxes do the same thing (at least when their DropDownStyle property is set to ComboBoxStyle.DropDownList).

我建议设置都具有这样的属性 FlatStyle.System 控件,除非你绝对需要不受此的FlatStyle支持。行为

I recommend setting all of the controls that have such a property to FlatStyle.System unless you absolutely require behavior not supported by this FlatStyle.

有几个其他异常。一些WinForms控件没有在Win32中存在,所以它们不会被本机控件的支持。该DataGridView这样的控制的一个很好的例子。

There are a couple of other exceptions. Some WinForms controls don't exist in Win32, so they aren't backed by native controls. The DataGridView is a good example of such a control.

最后,的MenuStrip 和ContextMenuStrip控件在C#code完全是书面和WinForms的手工绘制。他们不支持任何方式由本地Win32控件。这就是为什么他们看起来那么可怕丑陋的Windows Vista和更高,因为他们正在使用Office XP风格永远困。它看起来很酷的Windows XP,但它伸出像突兀在更高版本。改变从渲染风格Professional到System没有太大帮助,无论是。

Finally, the MenuStrip and ContextMenuStrip controls are written entirely in C# code and drawn manually by WinForms. They are not backed in any way by native Win32 controls. This is why they look so horribly ugly on Windows Vista and later, because they're forever stuck using the Office XP style. It looked cool on Windows XP, but it sticks out like a sore thumb on later versions. Changing the rendering style from Professional to System doesn't help very much, either.

相反,你需要添加原始版本这些控件,的MainMenu的和ContextMenu,到您的工具箱。他们并不默认包含在最近的Visual Studio版本,但他们绝对是仍然可以使用,并不会去任何地方。再次,我强烈建议,而不是使用这些,因为它们是由本地的Win32菜单支持100%,因此看起来,他们应该不管你的用户的Windows版本。

Instead, you need to add the original versions of these controls, MainMenu and ContextMenu, to your toolbox. They aren't included by default on recent versions of Visual Studio, but they are absolutely still available for use and aren't going anywhere. Again, I highly recommend using these instead, as they are backed 100% by the native Win32 menus and therefore look as they should regardless of your user's Windows version.