当前位置: 首页>>代码示例>>C#>>正文


C# PaintEventHandler代理代码示例

本文整理汇总了C#中System.Windows.Forms.PaintEventHandler代理的典型用法代码示例。如果您正苦于以下问题:C# PaintEventHandler代理的具体用法?C# PaintEventHandler怎么用?C# PaintEventHandler使用的例子?那么恭喜您, 这里精选的代理代码示例或许可以为您提供帮助。


PaintEventHandler代理属于System.Windows.Forms命名空间,在下文中一共展示了PaintEventHandler代理的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PictureBox

// This example creates a PictureBox control on the form and draws to it.
// This example assumes that the Form_Load event handler method is
// connected to the Load event of the form.

private PictureBox pictureBox1 = new PictureBox();
// Cache font instead of recreating font objects each time we paint.
private Font fnt = new Font("Arial",10);
private void Form1_Load(object sender, System.EventArgs e)
{
    // Dock the PictureBox to the form and set its background to white.
    pictureBox1.Dock = DockStyle.Fill;
    pictureBox1.BackColor = Color.White;
    // Connect the Paint event of the PictureBox to the event handler method.
    pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint);

    // Add the PictureBox control to the Form.
    this.Controls.Add(pictureBox1);
}

private void pictureBox1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
    // Create a local version of the graphics object for the PictureBox.
    Graphics g = e.Graphics;

    // Draw a string on the PictureBox.
    g.DrawString("This is a diagonal line drawn on the control",
        fnt, System.Drawing.Brushes.Blue, new Point(30,30));
    // Draw a line in the PictureBox.
    g.DrawLine(System.Drawing.Pens.Red, pictureBox1.Left, pictureBox1.Top,
        pictureBox1.Right, pictureBox1.Bottom);
}
开发者ID:.NET开发者,项目名称:System.Windows.Forms,代码行数:31,代码来源:PaintEventHandler

示例2: new PaintEventHandler

//引入命名空间
using System;
using System.Drawing;
using System.Windows.Forms;
   
class PaintTwoForms
{
     static Form form1, form2;
   
     public static void Main()
     {
          form1 = new Form();
          form2 = new Form();
   
          form1.Text      = "First Form";
          form1.BackColor = Color.White;
          form1.Paint    += new PaintEventHandler(MyPaintHandler);
   
          form2.Text      = "Second Form";
          form2.BackColor = Color.White;
          form2.Paint    += new PaintEventHandler(MyPaintHandler);
          form2.Show();
   
          Application.Run(form1);
     }
     static void MyPaintHandler(object objSender, PaintEventArgs pea)
     {
          Form     form = (Form)objSender;
          Graphics graphics = pea.Graphics;
          string   str;
   
          if(form == form1)
               str = "Hello from the first form";
          else
               str = "Hello from the second form";
   
          graphics.DrawString(str, form.Font, Brushes.Black, 0, 0);
     }
}
开发者ID:C#程序员,项目名称:System.Windows.Forms,代码行数:39,代码来源:PaintEventHandler


注:本文中的System.Windows.Forms.PaintEventHandler代理示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。