DrawTreeNodeEventArgs.State Özellik

Tanım

Çizecek öğesinin TreeNode geçerli durumunu alır.

public:
 property System::Windows::Forms::TreeNodeStates State { System::Windows::Forms::TreeNodeStates get(); };
public System.Windows.Forms.TreeNodeStates State { get; }
member this.State : System.Windows.Forms.TreeNodeStates
Public ReadOnly Property State As TreeNodeStates

Özellik Değeri

değerinin TreeNodeStates geçerli durumunu gösteren değerlerin bit düzeyinde birleşimi TreeNode.

Örnekler

Aşağıdaki kod örneği, sahip çizimini kullanarak denetimi TreeView özelleştirmeyi gösterir. Örnekteki TreeView denetim, standart düğüm etiketleriyle birlikte isteğe bağlı düğüm etiketlerini görüntüler. Düğüm etiketleri özelliği kullanılarak TreeNode.Tag belirtilir. Denetim TreeView ayrıca özel bir vurgu rengi de dahil olmak üzere özel renkler kullanır.

Renk özelliklerini ayarlayarak renklerin TreeView çoğunu özelleştirebilirsiniz, ancak seçim vurgu rengi özellik olarak kullanılamaz. Ayrıca, varsayılan seçim dikdörtgeni vurgulamak yalnızca bir düğüm etiketi çevresinde genişletir. Sahip çizimi, düğüm etiketlerini çizmek ve düğüm etiketi içerecek kadar büyük özelleştirilmiş bir vurgu dikdörtgeni çizmek için kullanılmalıdır.

Örnekte, olay işleyicisi TreeView.DrawNode düğüm etiketlerini çizer ve özel seçim el ile vurgulanır. Seçilmemiş düğümlerin özelleştirmeye ihtiyacı yoktur. Bunlar için, DrawDefault işletim sistemi tarafından çizilmeleri için true özelliği olarak ayarlanır.

Tam örnek için genel bakış başvuru konusuna DrawTreeNodeEventArgs bakın.

   // 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) != (TreeNodeStates)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.
         System::Drawing::Font^ nodeFont = e->Node->NodeFont;
         if ( nodeFont == nullptr )
                  nodeFont = (dynamic_cast<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 != nullptr )
      {
         e->Graphics->DrawString( e->Node->Tag->ToString(), tagFont, Brushes::Yellow, (float)e->Bounds.Right + 2, (float)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) != (TreeNodeStates)0 )
      {
         Pen^ focusPen = gcnew Pen( Color::Black );
         try
         {
            focusPen->DashStyle = System::Drawing::Drawing2D::DashStyle::Dot;
            Rectangle focusBounds = NodeBounds( e->Node );
            focusBounds.Size = System::Drawing::Size( focusBounds.Width - 1, focusBounds.Height - 1 );
            e->Graphics->DrawRectangle( focusPen, focusBounds );
         }
         finally
         {
            if ( focusPen )
               delete safe_cast<IDisposable^>(focusPen);
         }

      }
   }
// 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 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 (e.Node.Tag IsNot 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

Açıklamalar

Çizecek nesnenin TreeNode belirli bir durumda olup olmadığını denetlemek için bu özelliği kullanın. Bu özellik, düğüm hakkında yalnızca temel durum bilgilerini sağlar. Örneğin, bir düğümün seçili, işaretli veya odaklanmış olup olmadığını belirlemek için bu özelliği kullanabilirsiniz. Daha fazla bilgi sahibi olmanız gerekiyorsa, özelliği aracılığıyla Node düğümü alın. Örneğin, düğümün genişletilip genişletılmediğini belirlemek için düğümü almanız ve özelliğini denetlemeniz TreeNode.IsExpanded gerekir.

Şunlara uygulanır

Ayrıca bkz.