用C#實現截圖功能(3)(類似QQ截圖)

來源:互聯網
上載者:User

2,建立截圖主視窗

核心類MyRectangle已經完成,剩下的工作就是使用改類實現預想的截圖功能。

用VS2005 建立Project,命名為ScreenCutter。將主視窗命名為MainForm,建立一個視窗命名為ScreenBody,將其 ShowInTaskbar屬性設定為False,TopMost屬性設定為True,FormBorderStyle屬性設定為None,在 ScreenBody上添加一個panel控制項panel1,設定BackColor屬性為藍色,在panel1上添加相應個數的label,如 labelLocation、labelWidth、labelHeight等,用於指示當前選區位置和大小,panel1最終樣式為:

修改ScreenBody的引用命名空間為:

using System;
using System.Drawing;
using System.Windows.Forms;
在ScreenBody類中添加如下私人成員:
    private Graphics MainPainter; //the main painter
    private bool isDowned; //check whether the mouse is down
    private bool RectReady; //check whether the rectangle is finished
    private Image baseImage; //the back ground of the screen
    private Point moveModeDownPoint; //the mouse location when you move the rectangle
    private MyRectangle myRectangle; //the rectangle
    private bool moveMode; //check whether the rectangle is on move mode or not
    private bool changeSizeMode; //check whether the rectangle is on change size mode or not

修改ScreenBody建構函式:

public ScreenBody()
    {
      InitializeComponent();
      panel1.Location = new Point(this.Left, this.Top);
      myRectangle = new MyRectangle();
      moveModeDownPoint = new Point();
      this.Cursor = myRectangle.MyCursor;
    }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.