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

C#實現類似qq的屏幕截圖程序(2)

編輯:關於C語言

之後就是窗體的鼠標函數了,裡面很多代碼都沒有作出整理,看了一下,整理後的代碼應該會更少更精簡的

private void ScreenBody_DoubleClick(object sender, EventArgs e)
{
  if (((MouseEventArgs)e).Button == MouseButtons.Left &&Rect.Contains(((MouseEventArgs)e).X, ((MouseEventArgs)e).Y))
  {
    //保存的時候有很多種方法的......我這裡只用了這種
    Image memory = new Bitmap(Rect.Width, Rect.Height);
    Graphics g = Graphics.FromImage(memory);
    g.CopyFromScreen(Rect.X + 1, Rect.Y + 1, 0, 0, Rect.Size);
    Clipboard.SetImage(memory);
    this.Close();
  }
}

private void ScreenBody_MouseDown(object sender, MouseEventArgs e)
{
  if (e.Button == MouseButtons.Left)
  {
    isDowned = true;
    if (RectReady == false)
    {
      Rect.X = e.X;
      Rect.Y = e.Y;
      downPoint = new Point(e.X, e.Y);
    }
    if (RectReady == true)
    {
      tmpx = e.X;
      tmpy = e.Y;
    }
  }
  if (e.Button == MouseButtons.Right)
  {
    if (RectReady != true)
    {
      this.Close();
      return;
    }
    MainPainter.DrawImage(baseImage, 0, 0);
    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)
{

  if (RectReady == false)
  {
    if (isDowned == true)
    {
      Image New = DrawScreen((Image)baseImage.Clone(), e.X, e.Y);
      MainPainter.DrawImage(New, 0, 0);
      New.Dispose();
    }
  }
  if (RectReady == true)
  {
    if (Rect.Contains(e.X, e.Y))
    {
      //this.Cursor = Cursors.Hand;
      if (isDowned == true)
      {
        //和上一次的位置比較獲取偏移量
        Rect.X = Rect.X + e.X - tmpx;
        Rect.Y = Rect.Y + e.Y - tmpy;
        //記錄現在的位置
        tmpx = e.X;
        tmpy = e.Y;
        MoveRect((Image)baseImage.Clone(), Rect);
      }
    }
  }
}

private void ScreenBody_Load(object sender, EventArgs e)
{
  this.WindowState = FormWindowstate.Maximized;
  MainPainter = this.CreateGraphics();
  pen = new Pen(Brushes.Blue);
  isDowned = false;
  baseImage = this.BackgroundImage;
  Rect = new Rectangle();
  RectReady = false;
}

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