TreeNodeStates 列挙体とは? わかりやすく解説

TreeNodeStates 列挙体

メモ : この列挙体は、.NET Framework version 2.0新しく追加されたものです。

TreeNode に設定できる状態を表す定数定義します

この列挙体には、メンバ値のビットごとの組み合わせ可能にする FlagsAttribute 属性含まれています。

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

<FlagsAttribute> _
Public Enumeration TreeNodeStates
Dim instance As TreeNodeStates
[FlagsAttribute] 
public enum TreeNodeStates
[FlagsAttribute] 
public enum class TreeNodeStates
/** @attribute FlagsAttribute() */ 
public enum TreeNodeStates
FlagsAttribute 
public enum TreeNodeStates
メンバメンバ
解説解説
使用例使用例

オーナー描画使用して TreeView コントロールカスタマイズする方法次の例に示します。例で使用されている TreeView コントロールは、通常のノード ラベルのそばに、オプションノード タグ表示しますノード タグは、TreeNode.Tag プロパティ使用して指定されます。TreeView コントロールは、カスタム強調表示色を含むカスタム カラー使用します

TreeView の色の大半は、カラー プロパティ設定してカスタマイズできますが、選択内容強調表示する色については、プロパティとしてアクセスすることはできません。また、選択項目を強調表示する既定四角形は、ノード ラベル周囲についてのみ拡張されます。ノード タグ描画したり、ノード タグ全体表示できるようにカスタマイズされた強調表示用の四角形描画したりするには、オーナー描画使用する必要があります

この例では、TreeView.DrawNode イベントハンドラDrawTreeNodeEventArgs クラスメソッド呼び出して選択されていないノード描画ます。これらのメソッドは、カスタマイズする必要がない TreeView 要素既定外観提供します。このハンドラは、ノード タグおよびカスタム選択項目の強調表示手動描画ます。

詳細については、TreeView.DrawNodeリファレンス トピック参照してください

' Draws a node.
Private Sub myTreeView_DrawNode(ByVal
 sender As Object, _
    ByVal e As DrawTreeNodeEventArgs) Handles
 myTreeView.DrawNode

    ' Draw the background and node text for a selected node.
    If (e.State And TreeNodeStates.Selected)
 <> 0 Then

        ' Draw the background of the selected node. The NodeBounds
        ' method makes the highlight rectangle large enough to
        ' include the text of a node tag, if one is present.
        e.Graphics.FillRectangle(Brushes.Green, NodeBounds(e.Node))

        ' Retrieve the node font. If the node font has not been set
,
        ' use the TreeView font.
        Dim nodeFont As Font = e.Node.NodeFont
        If nodeFont Is Nothing
 Then
            nodeFont = CType(sender, TreeView).Font
        End If

        ' Draw the node text.
        e.Graphics.DrawString(e.Node.Text, nodeFont, Brushes.White, _
            e.Bounds.Left - 2, e.Bounds.Top)

    ' Use the default background and node text.
    Else
        e.DrawDefault = True
    End If

    ' If a node tag is present, draw its string representation 
    ' to the right of the label text.
    If Not (e.Node.Tag Is
 Nothing) Then
        e.Graphics.DrawString(e.Node.Tag.ToString(), tagFont, _
            Brushes.Yellow, e.Bounds.Right + 2, e.Bounds.Top)
    End If

    ' If the node has focus, draw the focus rectangle large, making
    ' it large enough to include the text of the node tag, if present.
    If (e.State And TreeNodeStates.Focused)
 <> 0 Then
        Dim focusPen As New
 Pen(Color.Black)
        Try
            focusPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot
            Dim focusBounds As Rectangle =
 NodeBounds(e.Node)
            focusBounds.Size = New Size(focusBounds.Width - 1,
 _
                focusBounds.Height - 1)
            e.Graphics.DrawRectangle(focusPen, focusBounds)
        Finally
            focusPen.Dispose()
        End Try
    End If

End Sub 'myTreeView_DrawNode
// Draws a node.
private void myTreeView_DrawNode(
    object sender, DrawTreeNodeEventArgs e)
{
    // Draw the background and node text for a selected node.
    if ((e.State & TreeNodeStates.Selected) != 0)
    {
        // Draw the background of the selected node. The NodeBounds
        // method makes the highlight rectangle large enough to
        // include the text of a node tag, if one is present.
        e.Graphics.FillRectangle(Brushes.Green, NodeBounds(e.Node));

        // Retrieve the node font. If the node font has not been set
,
        // use the TreeView font.
        Font nodeFont = e.Node.NodeFont;
        if (nodeFont == null) nodeFont = ((TreeView)sender).Font;

        // Draw the node text.
        e.Graphics.DrawString(e.Node.Text, nodeFont, Brushes.White,
            Rectangle.Inflate(e.Bounds, 2, 0));
    }

    // Use the default background and node text.
    else 
    {
        e.DrawDefault = true;
    }

    // If a node tag is present, draw its string representation 
    // to the right of the label text.
    if (e.Node.Tag != null)
    {
        e.Graphics.DrawString(e.Node.Tag.ToString(), tagFont,
            Brushes.Yellow, e.Bounds.Right + 2, e.Bounds.Top);
    }

    // If the node has focus, draw the focus rectangle large, making
    // it large enough to include the text of the node tag, if present.
    if ((e.State & TreeNodeStates.Focused) != 0)
    {
        using (Pen focusPen = new Pen(Color.Black))
        {
            focusPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
            Rectangle focusBounds = NodeBounds(e.Node);
            focusBounds.Size = new Size(focusBounds.Width - 1,
 
            focusBounds.Height - 1);
            e.Graphics.DrawRectangle(focusPen, focusBounds);
        }
    }
}
// Draws a node.
private void myTreeView_DrawNode(Object sender,
 DrawTreeNodeEventArgs e)
{
    // Draw the background and node text for a selected node.
    if ((int)(e.get_State() & TreeNodeStates.Selected)
 != 0) {
        // Draw the background of the selected node. The NodeBounds
        // method makes the highlight rectangle large enough to
        // include the text of a node tag, if one is present.
        e.get_Graphics().FillRectangle(Brushes.get_Green(),
            NodeBounds(e.get_Node()));
        // Retrieve the node font. If the node font has not been set
,
        // use the TreeView font.
        Font nodeFont = e.get_Node().get_NodeFont();
        if (nodeFont == null) {
            nodeFont = ((TreeView)sender).get_Font();
        }
        // Draw the node text.
        e.get_Graphics().DrawString(e.get_Node().get_Text(),
            nodeFont, Brushes.get_White(),
            RectangleF.op_Implicit(Rectangle.Inflate(e.get_Bounds(), 2, 0)));
    }
    // Use the default background and node text.
    else {
        e.set_DrawDefault(true);
    }
    // If a node tag is present, draw its string representation 
    // to the right of the label text.
    if (e.get_Node().get_Tag() != null) {
        e.get_Graphics().DrawString(e.get_Node().get_Tag().ToString(),
            tagFont, Brushes.get_Yellow(), e.get_Bounds().get_Right() + 2,
            e.get_Bounds().get_Top());
    }
    // If the node has focus, draw the focus rectangle large, making
    // it large enough to include the text of the node tag, if present.
    if ((int)(e.get_State() & TreeNodeStates.Focused)
 != 0) { 
        Pen focusPen = new Pen(Color.get_Black());
        try {
            focusPen.set_DashStyle(System.Drawing.Drawing2D.DashStyle.Dot);
            Rectangle focusBounds = NodeBounds(e.get_Node());
            focusBounds.set_Size(new Size(focusBounds.get_Width()
 - 1,
                focusBounds.get_Height() - 1));
            e.get_Graphics().DrawRectangle(focusPen, focusBounds);
        }
        finally {
            focusPen.Dispose();
        }            
    }
} //myTreeView_DrawNode
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
System.Windows.Forms 名前空間
DrawTreeNodeEventArgs クラス
DrawTreeNodeEventArgs.State プロパティ
TreeView.DrawNode



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

TreeNodeStates 列挙体のお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



TreeNodeStates 列挙体のページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS