• 鼠标坐标的记录


    private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
    {
      int originalWidth = this.pictureBox1.Image.Width;
      int originalHeight = this.pictureBox1.Image.Height;

      PropertyInfo rectangleProperty = this.pictureBox1.GetType().GetProperty("ImageRectangle", BindingFlags.Instance | BindingFlags.NonPublic);
      Rectangle rectangle = (Rectangle)rectangleProperty.GetValue(this.pictureBox1, null);

      int currentWidth = rectangle.Width;
      int currentHeight = rectangle.Height;

      double rate = (double)currentHeight / (double)originalHeight;

      int black_left_width = (currentWidth == this.pictureBox1.Width) ? 0 : (this.pictureBox1.Width - currentWidth) / 2;
      int black_top_height = (currentHeight == this.pictureBox1.Height) ? 0 : (this.pictureBox1.Height - currentHeight) / 2;

      int zoom_x = e.X - black_left_width;
      int zoom_y = e.Y - black_top_height;

      double original_x = (double)zoom_x * rate;
      double original_y = (double)zoom_y * rate;

      StringBuilder sb = new StringBuilder();

      sb.AppendFormat("原始尺寸{0}/{1}(宽/高)\r\n", originalWidth, originalHeight);
      sb.AppendFormat("缩放状态图片尺寸{0}/{1}(宽/高)\r\n", currentWidth, currentHeight);
      sb.AppendFormat("缩放比率{0}\r\n", rate);
      sb.AppendFormat("左留白宽度{0}\r\n", black_left_width);
      sb.AppendFormat("上留白高度{0}\r\n", black_top_height);
      sb.AppendFormat("当前鼠标坐标{0}/{1}(X/Y)\r\n", e.X, e.Y);
      sb.AppendFormat("缩放图中鼠标坐标{0}/{1}(X/Y)\r\n", zoom_x, zoom_y);
      sb.AppendFormat("原始图中鼠标坐标{0}/{1}(X/Y)\r\n", original_x, original_y);

      this.label1.Text = sb.ToString();
    }
  • 相关阅读:
    第04组 Beta冲刺(2/5)
    第04组 Beta冲刺(1/5)
    第04组 Alpha事后诸葛亮
    第04组 Alpha冲刺(6/6)
    第04组 Alpha冲刺(5/6)
    第04组 Alpha冲刺(4/6)
    第04组 Alpha冲刺(3/6)
    作业2-1:矩阵协方差
    作业lab1-1:lammps教程总结
    如何在服务器上传/下载文件
  • 原文地址:https://www.cnblogs.com/yannis/p/2088007.html
Copyright © 2020-2023  润新知