DrawToolTipEventArgs.AssociatedControl Özellik

Tanım

Çizilmekte olan ToolTip denetimi alır.

C#
public System.Windows.Forms.Control AssociatedControl { get; }
C#
public System.Windows.Forms.Control? AssociatedControl { get; }

Özellik Değeri

Control Olay gerçekleştiğinde Draw ile ToolTip ilişkili olan. Araç İpucu bir denetimle ilişkilendirilmemişse dönüş değeri olacaktır null .

Örnekler

Aşağıdaki kod örneğinde özel çizim işleminin nasıl yapılacağını gösterilmektedir ToolTip. Örnek bir ToolTip oluşturur ve üzerinde bulunan üç Button denetimle ilişkilendirir Form. Örnek, özelliğini olarak true ayarlar OwnerDraw ve olayı işlerDraw. Olay işleyicisindeDraw, ToolTip özelliği tarafından DrawToolTipEventArgs.AssociatedControl gösterildiği gibi hangi düğme ToolTip için görüntülendiğine bağlı olarak özel olarak çizilir.

Aşağıdaki kod örneği alıntısı özelliğinin nasıl kullanılacağını AssociatedControl gösterir. Kod örneğinin DrawToolTipEventArgs tamamı için sınıfa genel bakış bölümüne bakın.

C#
// Handles drawing the ToolTip.
private void toolTip1_Draw(System.Object sender, 
    System.Windows.Forms.DrawToolTipEventArgs e)
{
    // Draw the ToolTip differently depending on which 
    // control this ToolTip is for.
    // Draw a custom 3D border if the ToolTip is for button1.
    if (e.AssociatedControl == button1)
    {
        // Draw the standard background.
        e.DrawBackground();

        // Draw the custom border to appear 3-dimensional.
        e.Graphics.DrawLines(SystemPens.ControlLightLight, new Point[] {
            new Point (0, e.Bounds.Height - 1), 
            new Point (0, 0), 
            new Point (e.Bounds.Width - 1, 0)
        });
        e.Graphics.DrawLines(SystemPens.ControlDarkDark, new Point[] {
            new Point (0, e.Bounds.Height - 1), 
            new Point (e.Bounds.Width - 1, e.Bounds.Height - 1), 
            new Point (e.Bounds.Width - 1, 0)
        });

        // Specify custom text formatting flags.
        TextFormatFlags sf = TextFormatFlags.VerticalCenter |
                             TextFormatFlags.HorizontalCenter |
                             TextFormatFlags.NoFullWidthCharacterBreak;

        // Draw the standard text with customized formatting options.
        e.DrawText(sf);
    }
    // Draw a custom background and text if the ToolTip is for button2.
    else if (e.AssociatedControl == button2)
    {
        // Draw the custom background.
        e.Graphics.FillRectangle(SystemBrushes.ActiveCaption, e.Bounds);

        // Draw the standard border.
        e.DrawBorder();

        // Draw the custom text.
        // The using block will dispose the StringFormat automatically.
        using (StringFormat sf = new StringFormat())
        {
            sf.Alignment = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Center;
            sf.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.None;
            sf.FormatFlags = StringFormatFlags.NoWrap;
            using (Font f = new Font("Tahoma", 9))
            {
                e.Graphics.DrawString(e.ToolTipText, f, 
                    SystemBrushes.ActiveCaptionText, e.Bounds, sf);
            }
        }
    }
    // Draw the ToolTip using default values if the ToolTip is for button3.
    else if (e.AssociatedControl == button3)
    {
        e.DrawBackground();
        e.DrawBorder();
        e.DrawText();
    }
}

Açıklamalar

ToolTip yöntemi aracılığıyla ToolTip.SetToolTip birden çok denetimle ilişkilendirilebileceği için özelliği, AssociatedControl olayın hangi denetimle Draw ilişkili olduğunu belirlemek için kullanılabilir. İlişkili denetime göre farklı Araç İpucu özelleştirmesi gerçekleştirmek istiyorsanız 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

Ayrıca bkz.