當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。