DrawTreeNodeEventArgs.DrawDefault Özellik

Tanım

öğesinin sahip tarafından çizilmesi yerine işletim sistemi tarafından çizilip çizilmeyeceğini TreeNode belirten bir değer alır veya ayarlar.

C#
public bool DrawDefault { get; set; }

Özellik Değeri

true düğümün işletim sistemi tarafından çekilmesi gerekiyorsa; false düğüm olay işleyicisinde çizilecekse. false varsayılan değerdir.

Örnekler

Aşağıdaki kod örneği bu özelliğin kullanımını gösterir. Örnekte, olay işleyicisi TreeView.DrawNode düğüm etiketini ve seçilen düğüm için özel bir vurgu rengini el ile çizer. Seçili olmayan düğümlerin özelleştirmeye ihtiyacı yoktur. Seçilmemiş düğümler için, DrawDefault işletim sistemi tarafından çizilmeleri ve özelleştirilmiş bir görünüme sahip olmaması için true özelliği olarak ayarlanır.

Not

Bir düğümü el ile çizer ve ayrıca özelliğini olarak trueayarlarsanızDrawDefault, çizdiğiniz şeyin bir kısmı veya tümü işletim sistemi tarafından üzerine yazılabilir.

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

C#
// 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);
        }
    }
}

Açıklamalar

Olayı işlerken DrawNode özelleştirmek true istemediğiniz düğümler için bu özelliği olarak ayarlayın. Örneğin, yalnızca belirli bir durumdaki düğümleri özelleştirmek istediğinizde bu yararlı olur.

Şunlara uygulanır

Ürün Sürümler
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10