11.6 可视化窗口控件

请注意,在撰写本文时,Visual Studio Designer 对 .NET Core 的支持尚未成熟。.NET Core Windows Forms Designer 有一些变通方法和预览版。此外,您还可以选择手动编辑相关文件。以下文档使用 Visual Studio 和 .NET Framework 进行说明,在 .NET Core 中可以实现相同的应用程序功能。

根据项目所基于的图形子系统,Visual Studio 工具箱中会提供特定的窗口控件。

有关其他图形用户界面库的信息,参见 "使用其他图形用户界面库" 一节

HWindowControl 相比,智能窗口控件具有多项优势:

HSmartWindowControlWPF 不同,HSmartWindowControl 需要一个回调才能使用鼠标滚轮实现缩放:

private void WindowControl_Load(object sender, EventArgs e)
{
  this.MouseWheel += my_MouseWheel;
}

此外,您还需要转换鼠标坐标,使其相对于 HSmartWindowControl 的左上角。

private void my_MouseWheel(object sender, MouseEventArgs e)
{
    Point pt = windowControl.Location;
    MouseEventArgs newe = new MouseEventArgs(e.Button, e.Clicks, 
                                                 e.X - pt.X, e.Y - pt.Y, e.Delta);
    windowControl.HSmartWindowControl_MouseWheel(sender, newe);
}

使用智能窗口控件可以触发以下事件并对其做出反应:

并非所有算子都能与智能窗口控件一起使用。支持以下算子:

取而代之的是使用绘图对象。

在以下章节中,为简单起见,将使用 HSmartWindowControl 这一术语。如果您的项目基于 WPF,请将其理解为 HSmartWindowControlWPF。这同样适用于旧版本的 HWindowControl