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


C# Graphics.CopyFromScreen方法代码示例

本文整理汇总了C#中System.Drawing.Graphics.CopyFromScreen方法的典型用法代码示例。如果您正苦于以下问题:C# Graphics.CopyFromScreen方法的具体用法?C# Graphics.CopyFromScreen怎么用?C# Graphics.CopyFromScreen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Drawing.Graphics的用法示例。


在下文中一共展示了Graphics.CopyFromScreen方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CopyPixels4

private void CopyPixels4(PaintEventArgs e)
{
    e.Graphics.CopyFromScreen(0, 0, 20, 20, new Size(160, 160), 
        CopyPixelOperation.SourceInvert);
}
开发者ID:.NET开发者,项目名称:System.Drawing,代码行数:5,代码来源:Graphics.CopyFromScreen

示例2: Button

//引入命名空间
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Printing;

public class Form1 :
    Form
{
    private Button printButton = new Button();
    private PrintDocument printDocument1 = new PrintDocument();

    public Form1()
    {
        printButton.Text = "Print Form";
        printButton.Click += new EventHandler(printButton_Click);
        printDocument1.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage);
        this.Controls.Add(printButton);
    }

    void printButton_Click(object sender, EventArgs e)
    {
        CaptureScreen();
        printDocument1.Print();
    }

    Bitmap memoryImage;

    private void CaptureScreen()
    {
        Graphics myGraphics = this.CreateGraphics();
        Size s = this.Size;
        memoryImage = new Bitmap(s.Width, s.Height, myGraphics);
        Graphics memoryGraphics = Graphics.FromImage(memoryImage);
        memoryGraphics.CopyFromScreen(this.Location.X, this.Location.Y, 0, 0, s);
    }

    private void printDocument1_PrintPage(System.Object sender,  
           System.Drawing.Printing.PrintPageEventArgs e)
    {
        e.Graphics.DrawImage(memoryImage, 0, 0);
    }

    public static void Main()
    {
        Application.Run(new Form1());
    }
}
开发者ID:.NET开发者,项目名称:System.Drawing,代码行数:48,代码来源:Graphics.CopyFromScreen

示例3: CopyPixels1

private void CopyPixels1(PaintEventArgs e)
{
    e.Graphics.CopyFromScreen(this.Location, 
        new Point(40, 40), new Size(100, 100));
}
开发者ID:.NET开发者,项目名称:System.Drawing,代码行数:5,代码来源:Graphics.CopyFromScreen

示例4: CopyPixels2

private void CopyPixels2(PaintEventArgs e)
{
    e.Graphics.CopyFromScreen(this.Location, new Point(40, 40), 
        new Size(100, 100), CopyPixelOperation.MergePaint); 
}
开发者ID:.NET开发者,项目名称:System.Drawing,代码行数:5,代码来源:Graphics.CopyFromScreen

示例5: Form1

//引入命名空间
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
using System.Drawing.Drawing2D;

public class Form1 : Form
{
        private System.Windows.Forms.Panel panel1;
        private System.Windows.Forms.Button cmdCapture;
        private System.Windows.Forms.PictureBox pictureBox1;

      public Form1() {
            InitializeComponent();
            
      }

        private void cmdCapture_Click(object sender, EventArgs e)
        {
            if (pictureBox1.Image != null) pictureBox1.Image.Dispose();

            Bitmap bmp = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
            Graphics g = Graphics.FromImage(bmp);
            g.CopyFromScreen(0, 0, 0, 0, bmp.Size);
            g.Dispose();
            pictureBox1.Image = bmp;
            pictureBox1.Size = bmp.Size;
        }

        private void InitializeComponent()
        {
            this.panel1 = new System.Windows.Forms.Panel();
            this.cmdCapture = new System.Windows.Forms.Button();
            this.pictureBox1 = new System.Windows.Forms.PictureBox();
            this.panel1.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
            this.SuspendLayout();

            this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                        | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.panel1.AutoScroll = true;
            this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.panel1.Controls.Add(this.pictureBox1);
            this.panel1.Location = new System.Drawing.Point(8, 8);
            this.panel1.Size = new System.Drawing.Size(270, 233);

            this.cmdCapture.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.cmdCapture.Location = new System.Drawing.Point(169, 249);
            this.cmdCapture.Size = new System.Drawing.Size(110, 30);
            this.cmdCapture.Text = "Capture Screen";
            this.cmdCapture.UseVisualStyleBackColor = true;
            this.cmdCapture.Click += new System.EventHandler(this.cmdCapture_Click);

            this.pictureBox1.Location = new System.Drawing.Point(0, 0);
            this.pictureBox1.Size = new System.Drawing.Size(100, 50);
            this.pictureBox1.TabStop = false;

            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(290, 288);
            this.Controls.Add(this.cmdCapture);
            this.Controls.Add(this.panel1);
            this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.Text = "Screen Capture";
            this.panel1.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
            this.ResumeLayout(false);

        }
      [STAThread]
      static void Main()
      {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
      }
}
开发者ID:C#程序员,项目名称:System.Drawing,代码行数:83,代码来源:Graphics.CopyFromScreen


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