程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> 用C#實現截圖功能(3)(類似QQ截圖)(2)

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

編輯:關於C語言

添加ScreenBody窗口的DoubleClick、MouseDown、MouseUp、MouseMove及Load事件代碼:

private void ScreenBody_DoubleClick(object sender, EventArgs e)
    {
      if (((MouseEventArgs)e).Button == MouseButtons.Left && myRectangle.Contains(((MouseEventArgs)e).X, ((MouseEventArgs)e).Y))
      {
        panel1.Visible = false;
        MainPainter.DrawImage(baseImage, 0, 0);
        Image memory = new Bitmap(myRectangle.Width, myRectangle.Height);
        Graphics g = Graphics.FromImage(memory);
        g.CopyFromScreen(myRectangle.X, myRectangle.Y, 0, 0, myRectangle.Size);
        Clipboard.SetImage(memory);
        this.Close();
      }
    }
    private void ScreenBody_MouseDown(object sender, MouseEventArgs e)
    {
      if (e.Button == MouseButtons.Left)
      {
        isDowned = true;
        if (!RectReady)
        {
          myRectangle.DownPointX = e.X;
          myRectangle.DownPointY = e.Y;
          myRectangle.X = e.X;
          myRectangle.Y = e.Y;
        }
        if (RectReady == true)
        {
          moveModeDownPoint = new Point(e.X, e.Y);  
        }
      }
      if (e.Button == MouseButtons.Right)
      {
        if (!RectReady)
        {
          this.Close();
          return;
        }
        MainPainter.DrawImage(baseImage, 0, 0);
        myRectangle.Initialize(0, 0, 0, 0);
        myRectangle.setAllModeFalse();
        this.Cursor = myRectangle.MyCursor;
        RectReady = false;
      }
    }
    private void ScreenBody_MouseUp(object sender, MouseEventArgs e)
    {
      if (e.Button == MouseButtons.Left)
      {
        isDowned = false;
        RectReady = true;
      }
    }
    private void ScreenBody_MouseMove(object sender, MouseEventArgs e)
    {
      labelWidth.Text = myRectangle.Width.ToString();
      labelHeight.Text = myRectangle.Height.ToString();
      labelLocation.Text = "X "+myRectangle.X.ToString() + ", Y " + myRectangle.Y.ToString();
      if (!RectReady)
      {
        if (isDowned)
        {
          myRectangle.Draw(e, this.BackColor);
        }
      }
      else
      {
        myRectangle.CheckMouseLocation(e);
        this.Cursor = myRectangle.MyCursor;
        this.changeSizeMode = myRectangle.ChangeSizeMode;
        this.moveMode = myRectangle.MoveMode&&myRectangle.Contains(moveModeDownPoint.X,moveModeDownPoint.Y);
        if (changeSizeMode)
        {
          this.moveMode = false;
          myRectangle.Draw(BackColor);
          myRectangle.ChangeSize(e);
          myRectangle.Draw(BackColor);
        }
        if (moveMode)
        {
          this.changeSizeMode = false;
          myRectangle.Draw(BackColor);
          myRectangle.X = myRectangle.X + e.X - moveModeDownPoint.X;
          myRectangle.Y = myRectangle.Y + e.Y - moveModeDownPoint.Y;
          moveModeDownPoint.X = e.X;
          moveModeDownPoint.Y = e.Y;
          myRectangle.Draw(this.BackColor);
        }
      }
    }
    private void ScreenBody_Load(object sender, EventArgs e)
    {
      this.WindowState = FormWindowstate.Maximized;
      MainPainter = this.CreateGraphics();
      isDowned = false;
      baseImage = this.BackgroundImage;
      panel1.Visible = true;
      RectReady = false;
      changeSizeMode = false;
      moveMode = false;
    }

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved