如何处理表单PainEvent [英] how to handle the forms PainEvent

查看:82
本文介绍了如何处理表单PainEvent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个表单,我想在其中执行以下代码





I have created a form in which i want to execute the following code


public void DrawVisualStyleElementExplorerBarHeaderPin1(PaintEventArgs e)
{
    if (VisualStyleRenderer.IsElementDefined(
        VisualStyleElement.ExplorerBar.HeaderPin.Normal))
    {
        VisualStyleRenderer renderer =
             new VisualStyleRenderer(VisualStyleElement.ExplorerBar.HeaderPin.Normal);
        Rectangle rectangle1 = new Rectangle(10, 50, 50, 50);
        renderer.DrawBackground(e.Graphics, rectangle1);
        e.Graphics.DrawString("VisualStyleElement.ExplorerBar.HeaderPin.Normal",
             this.Font, Brushes.Black, new Point(10, 10));
    }
    else
        e.Graphics.DrawString("This element is not defined in the current visual style.",
             this.Font, Brushes.Black, new Point(10, 10));
}





我不知道如何使用这段代码。我的大四学生告诉我使用这个代码,他已经给出了如下链接

请帮助你摆脱它。

链接是: - http://msdn.microsoft.com/en-us/library/system.windows.forms.visualstyles.visualstyleelement.explorerbar.headerpin.aspx?cs-save-lang=1&cs -lang = csharp [ ^ ]

推荐答案





添加油漆事件 [ ^ ]到您的表单:

Hi,

Add a Paint event[^] to your form:
public Form1()
{
     InitializeComponent();
     this.Paint += Form1_Paint;
}



并且在 Form1_Paint 方法中:


And in the Form1_Paint method:

private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
     DrawVisualStyleElementExplorerBarHeaderPin1(e);
}



希望这会有所帮助。


Hope this helps.


private void InitializeComponent()
{
............
            this.Name = "Form1";
            this.Text = "Form1";
            this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
            this.ResumeLayout(false);

}










public Form1()
{
            InitializeComponent();
}

private void Form1_Paint(object sender, PaintEventArgs e)
{
            DrawVisualStyleElementExplorerBarHeaderPin1(e);
}


这篇关于如何处理表单PainEvent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆