HtmlTextWriter.Indent プロパティ

定義

マークアップの各行の開始位置のインデントを設定するタブ位置の数を取得または設定します。

public:
 property int Indent { int get(); void set(int value); };
public int Indent { get; set; }
member this.Indent : int with get, set
Public Property Indent As Integer

プロパティ値

Int32

各行のインデントを設定するタブ位置の数。

次のコード例は、要素の開始タグ<span>Indent属性が追加され、メソッドが呼び出されたときにプロパティに割り当てられる値をインクリメントする方法をRenderBeginTag示しています。 これにより、要素内にレンダリングされるすべてのマークアップのインデントが <span> 増加します。

// Set attributes and values along with attributes and styles  
// attribute defined for a <span> element.
writer.AddAttribute(HtmlTextWriterAttribute.Onclick, "alert('Hello');");
writer.AddAttribute("CustomAttribute", "CustomAttributeValue");
writer.AddStyleAttribute(HtmlTextWriterStyle.Color, "Red");
writer.AddStyleAttribute("Customstyle", "CustomStyleValue");
writer.RenderBeginTag(HtmlTextWriterTag.Span);
// Create a space and indent the markup inside the 
// <span> element.
writer.WriteLine();
writer.Indent++;
' Set attributes and values along with attributes and styles
' attribute defined for a <span> element.
writer.AddAttribute(HtmlTextWriterAttribute.Onclick, "alert('Hello');")
writer.AddAttribute("CustomAttribute", "CustomAttributeValue")
writer.AddStyleAttribute(HtmlTextWriterStyle.Color, "Red")
writer.AddStyleAttribute("CustomStyle", "CustomStyleValue")
writer.RenderBeginTag(HtmlTextWriterTag.Span)

'  Create a space and indent the markup inside the 
' <span> element.
writer.WriteLine()
writer.Indent += 1

注釈

インデントは、コンストラクターのパラメーターHtmlTextWriter(TextWriter, String)で指定された文字列をtabString、プロパティでIndent指定された回数だけ書き込むことで実行されます。

プロパティが負の Indent 値に設定されている場合は、保存される前に 0 に変更されます。

適用対象

こちらもご覧ください