LoginDesigner.GetDesignTimeHtml(DesignerRegionCollection) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取用于在设计时呈现关联控件的标记,并填充设计器区域的集合。
public:
override System::String ^ GetDesignTimeHtml(System::Web::UI::Design::DesignerRegionCollection ^ regions);
public override string GetDesignTimeHtml (System.Web.UI.Design.DesignerRegionCollection regions);
override this.GetDesignTimeHtml : System.Web.UI.Design.DesignerRegionCollection -> string
Public Overrides Function GetDesignTimeHtml (regions As DesignerRegionCollection) As String
参数
- regions
- DesignerRegionCollection
一个 DesignerRegionCollection,将在其中添加控件设计时视图中定义的可选择和可单击区域。
返回
一个字符串,其中包含用于在设计时呈现 Login 的标记。
示例
下面的代码示例演示如何重写 GetDesignTimeHtml 从 LoginDesigner 类继承的类中的 方法,以更改设计时派生自 控件的 Login 控件的外观。 如果 BorderStyle 控件的 属性为 NotSet 或 None 值,则本示例在控件周围绘制蓝色虚线边框,使其范围更可见。
// Generate the design-time markup.
public override string GetDesignTimeHtml()
{
// Make the control more visible in the designer. If the border
// style is None or NotSet, change the border to a blue dashed line.
MyLogin myLoginCtl = (MyLogin)ViewControl;
string markup = null;
// Check if the border style should be changed.
if (myLoginCtl.BorderStyle == BorderStyle.NotSet ||
myLoginCtl.BorderStyle == BorderStyle.None)
{
BorderStyle oldBorderStyle = myLoginCtl.BorderStyle;
Color oldBorderColor = myLoginCtl.BorderColor;
// Set the design time properties and catch any exceptions.
try
{
myLoginCtl.BorderStyle = BorderStyle.Dashed;
myLoginCtl.BorderColor = Color.Blue;
// Call the base method to generate the markup.
markup = base.GetDesignTimeHtml();
}
catch (Exception ex)
{
markup = GetErrorDesignTimeHtml(ex);
}
finally
{
// It is not necessary to restore the border properties
// to their original values because the ViewControl
// was used to reference the associated control and the
// UsePreviewControl was not overridden.
// myLoginCtl.BorderStyle = oldBorderStyle;
// myLoginCtl.BorderColor = oldBorderColor;
}
}
else
{
// Call the base method to generate the markup.
markup = base.GetDesignTimeHtml();
}
return markup;
} // GetDesignTimeHtml
' Generate the design-time markup.
Public Overrides Function GetDesignTimeHtml() As String
' Make the control more visible in the designer. If the border
' style is None or NotSet, change the border to a blue dashed line.
Dim myLoginCtl As MyLogin = CType(ViewControl, MyLogin)
Dim markup As String = Nothing
' Check if the border style should be changed.
If (myLoginCtl.BorderStyle = BorderStyle.NotSet Or _
myLoginCtl.BorderStyle = BorderStyle.None) Then
Dim oldBorderStyle As BorderStyle = myLoginCtl.BorderStyle
Dim oldBorderColor As Color = myLoginCtl.BorderColor
' Set the design time properties and catch any exceptions.
Try
myLoginCtl.BorderStyle = BorderStyle.Dashed
myLoginCtl.BorderColor = Color.Blue
' Call the base method to generate the markup.
markup = MyBase.GetDesignTimeHtml()
Catch ex As Exception
markup = GetErrorDesignTimeHtml(ex)
Finally
' It is not necessary to restore the border properties
' to their original values because the ViewControl
' was used to reference the associated control and the
' UsePreviewControl was not overridden.
' myLoginCtl.BorderStyle = oldBorderStyle
' myLoginCtl.BorderColor = oldBorderColor
End Try
Else
' Call the base method to generate the markup.
markup = MyBase.GetDesignTimeHtml()
End If
Return markup
End Function ' GetDesignTimeHtml
注解
方法GetDesignTimeHtml为LayoutTemplate关联Login控件的 属性创建一个 EditableDesignerRegion 对象,并将其添加到 DesignerRegionCollection 参数regions
引用的 对象。 方法 GetDesignTimeHtml 使用 GetDesignTimeHtml 基方法为控件的设计时呈现 Login 生成标记。
继承者说明
如果重写 GetDesignTimeHtml(DesignerRegionCollection) 方法,请务必调用 GetDesignTimeHtml() 基方法,因为它最终会通过多个重写级别调用 Login 控件或控件的副本来生成标记。