ViewTechnology 枚举
定义设计器宿主所支持的技术集的标识符。
**命名空间:**System.ComponentModel.Design
**程序集:**System(在 system.dll 中)
语法
声明
<ComVisibleAttribute(True)> _
Public Enumeration ViewTechnology
用法
Dim instance As ViewTechnology
[ComVisibleAttribute(true)]
public enum ViewTechnology
[ComVisibleAttribute(true)]
public enum class ViewTechnology
/** @attribute ComVisibleAttribute(true) */
public enum ViewTechnology
ComVisibleAttribute(true)
public enum ViewTechnology
成员
成员名称 | 说明 | |
---|---|---|
Default | 指定默认的视图技术支持。
根设计器可以返回任何类型的对象,但返回的对象必须兼容宿主的技术适配器。宿主环境,如 Visual Studio,提供了一种插入新视图技术适配器的方法。Windows 窗体设计器的默认视图对象是一个 System.Windows.Forms.Control 实例。 |
|
Passthrough | 表示将视图对象直接传递给开发环境的模式。
查看对象必须实现开发环境所要求的任何接口。Visual Studio 开发环境支持的查看对象可以是 ActiveX 控件、活动文档或通过 Visual Studio VSI(Visual Studio 集成)程序提供的实现 IVsWindowPane 接口的对象。Visual Studio 开发环境提供对此视图技术的支持。对此视图技术的支持并不一定可用于所有开发环境。 |
|
WindowsForms | 表示由 Windows 窗体控件对象为根设计器提供显示的模式。
设计器宿主将用 Windows 窗体控件填充开发环境文档窗口。 |
备注
视图适配器模型可取代 ViewTechnology 功能并增加了一些其他功能;不过,您仍然可以选择保留 ViewTechnology 功能以保持向后兼容以及将来使用。有关更多信息,请参见位于 http://windowsforms.net/articles/shapedesigner.aspx 的 Windows 窗体知识库中的“.NET 形状库:一个简单的设计器”(英文)。
ViewTechnology 定义的标识符可指示在控制设计器承载文档的显示所采用的模式。
在设计器宿主环境中,只应使用 Default 值。在 .NET Framework 以前的版本中,ViewTechnology 枚举指定根设计器支持的 UI 模型的类型。因为这个模型不是可扩展的,所以应改用视图适配器模型。视图适配器是一个类型,用于使一种类型的对象适应于另一种类型。
例如,一个 HTML 设计器可能返回一个 DemoDOM
树作为其视图。HTML 设计器返回 Default 的视图技术。一个 Windows 窗体宿主环境应有一个或者更多可用的视图适配器类。如果有这样一个类可以将 DemoDOM
转换成 Windows 窗体控件,则宿主应用程序就可以支持此设计器类型。如果没有适配器可以处理从设计器的 GetView 方法返回的数据类型,设计器的加载将会失败,同时显示一个错误给用户。
Visual Studio 有一套用于提供视图适配器的可扩展方案,因而可适应于任何 UI 技术。第三方技术提供者也可以提供适当的视图适配器,而且他们的对象模型马上就可以使用。
有关使用视图适配器的示例,请参见位于 http://windowsforms.net/articles/shapedesigner.aspx 的 Windows 窗体知识库中的“.NET 形状库:一个简单的设计器”(英文)。
示例
下面的代码示例演示如何在设计器中使用 ViewTechnology 类。此代码示例摘自为 IRootDesigner 接口提供的一个更大的示例。
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Diagnostics
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Windows.Forms.Design
Namespace SampleRootDesigner
' This sample demonstrates how to provide the root designer view, or
' design mode background view, by overriding IRootDesigner.GetView().
' This sample component inherits from RootDesignedComponent which
' uses the SampleRootDesigner.
Public Class RootViewSampleComponent
Inherits RootDesignedComponent
Public Sub New()
End Sub
End Class
' The following attribute associates the SampleRootDesigner designer
' with the SampleComponent component.
<Designer(GetType(SampleRootDesigner), GetType(IRootDesigner))> _
Public Class RootDesignedComponent
Inherits Component
Public Sub New()
End Sub
End Class
Public Class SampleRootDesigner
Inherits ComponentDesigner
Implements IRootDesigner
' Member field of custom type RootDesignerView, a control that
' will be shown in the Forms designer view. This member is
' cached to reduce processing needed to recreate the
' view control on each call to GetView().
Private m_view As RootDesignerView
' This method returns an instance of the view for this root
' designer. The "view" is the user interface that is presented
' in a document window for the user to manipulate.
Function GetView(ByVal technology As ViewTechnology) As Object Implements IRootDesigner.GetView
If Not technology = ViewTechnology.Default Then
Throw New ArgumentException("Not a supported view technology", "technology")
End If
If m_view Is Nothing Then
' Some type of displayable Form or control is required for a root designer that overrides
' GetView(). In this example, a Control of type RootDesignerView is used.
' Any class that inherits from Control will work.
m_view = New RootDesignerView(Me)
End If
Return m_view
End Function
' IRootDesigner.SupportedTechnologies is a required override for an
' IRootDesigner. Default is the view technology used by this designer.
ReadOnly Property SupportedTechnologies() As ViewTechnology() Implements IRootDesigner.SupportedTechnologies
Get
Return New ViewTechnology() {ViewTechnology.Default}
End Get
End Property
' RootDesignerView is a simple control that will be displayed
' in the designer window.
Private Class RootDesignerView
Inherits Control
Private m_designer As SampleRootDesigner
Public Sub New(ByVal designer As SampleRootDesigner)
m_designer = designer
BackColor = Color.Blue
Font = New Font(Font.FontFamily.Name, 24.0F)
End Sub
Protected Overrides Sub OnPaint(ByVal pe As PaintEventArgs)
MyBase.OnPaint(pe)
' Draws the name of the component in large letters.
Dim rf As New RectangleF(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width, ClientRectangle.Height)
pe.Graphics.DrawString(m_designer.Component.Site.Name, Font, Brushes.Yellow, rf)
End Sub
End Class
End Class
End Namespace
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.Design;
namespace SampleRootDesigner
{
// This sample demonstrates how to provide the root designer view, or
// design mode background view, by overriding IRootDesigner.GetView().
// This sample component inherits from RootDesignedComponent which
// uses the SampleRootDesigner.
public class RootViewSampleComponent : RootDesignedComponent
{
public RootViewSampleComponent()
{
}
}
// The following attribute associates the SampleRootDesigner designer
// with the SampleComponent component.
[Designer(typeof(SampleRootDesigner), typeof(IRootDesigner))]
public class RootDesignedComponent : Component
{
public RootDesignedComponent()
{
}
}
public class SampleRootDesigner : ComponentDesigner, IRootDesigner
{
// Member field of custom type RootDesignerView, a control that
// will be shown in the Forms designer view. This member is
// cached to reduce processing needed to recreate the
// view control on each call to GetView().
private RootDesignerView m_view;
// This method returns an instance of the view for this root
// designer. The "view" is the user interface that is presented
// in a document window for the user to manipulate.
object IRootDesigner.GetView(ViewTechnology technology)
{
if (technology != ViewTechnology.Default)
{
throw new ArgumentException("Not a supported view technology", "technology");
}
if (m_view == null)
{
// Some type of displayable Form or control is required
// for a root designer that overrides GetView(). In this
// example, a Control of type RootDesignerView is used.
// Any class that inherits from Control will work.
m_view = new RootDesignerView(this);
}
return m_view;
}
// IRootDesigner.SupportedTechnologies is a required override for an
// IRootDesigner. Default is the view technology used by this designer.
ViewTechnology[] IRootDesigner.SupportedTechnologies
{
get
{
return new ViewTechnology[] {ViewTechnology.Default};
}
}
// RootDesignerView is a simple control that will be displayed
// in the designer window.
private class RootDesignerView : Control
{
private SampleRootDesigner m_designer;
public RootDesignerView(SampleRootDesigner designer)
{
m_designer = designer;
BackColor = Color.Blue;
Font = new Font(Font.FontFamily.Name, 24.0f);
}
protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
// Draws the name of the component in large letters.
pe.Graphics.DrawString(m_designer.Component.Site.Name, Font, Brushes.Yellow, ClientRectangle);
}
}
}
}
package SampleRootDesigner;
import System.*;
import System.Collections.*;
import System.ComponentModel.*;
import System.ComponentModel.Design.*;
import System.Diagnostics.*;
import System.Drawing.*;
import System.Windows.Forms.*;
import System.Windows.Forms.Design.*;
// This sample demonstrates how to provide the root designer view, or
// design mode background view, by overriding IRootDesigner.GetView().
// This sample component inherits from RootDesignedComponent which
// uses the SampleRootDesigner.
public class RootViewSampleComponent extends RootDesignedComponent
{
public RootViewSampleComponent()
{
} //RootViewSampleComponent
} //RootViewSampleComponent
// The following attribute associates the SampleRootDesigner designer
// with the SampleComponent component.
/** @ attribute Designer(SampleRootDesigner .class.ToType(),
IRootDesigner .class.ToType())
*/
public class RootDesignedComponent extends Component
{
public RootDesignedComponent()
{
} //RootDesignedComponent
} //RootDesignedComponent
public class SampleRootDesigner extends ComponentDesigner
implements IRootDesigner
{
// Member field of custom type RootDesignerView, a control that
// will be shown in the Forms designer view. This member is
// cached to reduce processing needed to recreate the
// view control on each call to GetView().
private RootDesignerView mView;
// This method returns an instance of the view for this root
// designer. The "view" is the user interface that is presented
// in a document window for the user to manipulate.
public Object GetView(ViewTechnology technology)
{
if (!(technology.Equals(ViewTechnology.WindowsForms))) {
throw new ArgumentException(
"Not a supported view technology", "technology");
}
if (mView == null) {
// Some type of displayable Form or control is required
// for a root designer that overrides GetView(). In this
// example, a Control of type RootDesignerView is used.
// Any class that inherits from Control will work.
mView = new RootDesignerView(this);
}
return mView;
} //GetView
// IRootDesigner.SupportedTechnologies is a required override for an
// IRootDesigner. WindowsForms is the view technology used by this designer.
/** @property
*/
public ViewTechnology[] get_SupportedTechnologies()
{
return new ViewTechnology[] { ViewTechnology.WindowsForms };
} //get_SupportedTechnologies
// RootDesignerView is a simple control that will be displayed
// in the designer window.
private class RootDesignerView extends Control
{
private SampleRootDesigner mDesigner;
public RootDesignerView(SampleRootDesigner designer)
{
mDesigner = designer;
set_BackColor(Color.get_Blue());
set_Font(new Font(get_Font().get_FontFamily().get_Name(), 24));
} //RootDesignerView
protected void OnPaint(PaintEventArgs pe)
{
super.OnPaint(pe);
// Draws the name of the component in large letters.
pe.get_Graphics().DrawString(
mDesigner.get_Component().get_Site().get_Name(),
get_Font(), Brushes.get_Yellow(),
RectangleF.op_Implicit(get_ClientRectangle()));
} //OnPaint
} //RootDesignerView
} //SampleRootDesigner
平台
Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0