MenuDesigner.GetDesignTimeHtml 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得在設計階段用來呈現關聯控制項的標記。
public:
override System::String ^ GetDesignTimeHtml();
public override string GetDesignTimeHtml ();
override this.GetDesignTimeHtml : unit -> string
Public Overrides Function GetDesignTimeHtml () As String
傳回
字串,包含在設計階段用來呈現 Menu 的標記。
範例
下列程式代碼範例示範如何在繼承自 MenuDesigner 類別的類別中覆寫 GetDesignTimeHtml 方法。 覆寫的方法會變更在設計時間衍生自 Menu 控件的控件外觀。 如果控件的 屬性是 NotSet 或 None 值,此範例會繪製控件周圍的橙色虛線框線,BorderStyle使其範圍更可見。
// 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 an orange dotted line.
MyMenu myMenuCtl = (MyMenu)ViewControl;
string markup = null;
// Check if the border style should be changed.
if (myMenuCtl.BorderStyle == BorderStyle.NotSet ||
myMenuCtl.BorderStyle == BorderStyle.None)
{
BorderStyle oldBorderStyle = myMenuCtl.BorderStyle;
Color oldBorderColor = myMenuCtl.BorderColor;
// Set the design-time properties and catch any exceptions.
try
{
myMenuCtl.BorderStyle = BorderStyle.Dotted;
myMenuCtl.BorderColor = Color.FromArgb(0xFF7F00);
// Call the base method to generate the markup.
markup = base.GetDesignTimeHtml();
}
catch (Exception ex)
{
markup = GetErrorDesignTimeHtml(ex);
}
finally
{
// Restore the properties to their original settings.
myMenuCtl.BorderStyle = oldBorderStyle;
myMenuCtl.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 an orange dotted line.
Dim myMenuCtl As MyMenu = CType(ViewControl, MyMenu)
Dim markup As String = Nothing
' Check if the border style should be changed.
If (myMenuCtl.BorderStyle = BorderStyle.NotSet Or _
myMenuCtl.BorderStyle = BorderStyle.None) Then
Dim oldBorderStyle As BorderStyle = myMenuCtl.BorderStyle
Dim oldBorderColor As Color = myMenuCtl.BorderColor
' Set the design-time properties and catch any exceptions.
Try
myMenuCtl.BorderStyle = BorderStyle.Dotted
myMenuCtl.BorderColor = Color.FromArgb(&HFF7F00)
' Call the base method to generate the markup.
markup = MyBase.GetDesignTimeHtml()
Catch ex As Exception
markup = GetErrorDesignTimeHtml(ex)
Finally
' Restore the properties to their original settings.
myMenuCtl.BorderStyle = oldBorderStyle
myMenuCtl.BorderColor = oldBorderColor
End Try
Else
' Call the base method to generate the markup.
markup = MyBase.GetDesignTimeHtml()
End If
Return markup
End Function ' GetDesignTimeHtml
備註
方法 GetDesignTimeHtml 會 DataBind 呼叫 方法,將設計時間數據源系結至相關聯的 Menu 控件,然後 GetDesignTimeHtml 呼叫 GetDesignModeState 方法,讓 Menu 控件產生其靜態檢視和動態檢視。 會 GetDesignTimeHtml 傳回目前檢視的標記。 如果未定義目前的檢視,則會 GetDesignTimeHtml 呼叫 GetDesignTimeHtml 基底方法。