版博士V2.0程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

203 lines
8.6 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. namespace ProductionControl
  11. {
  12. public partial class Form1 : Form
  13. {
  14. public Form1()
  15. {
  16. InitializeComponent();
  17. }
  18. private void button1_Click(object sender, EventArgs e)
  19. {
  20. try
  21. {
  22. //int ret = API.GWQ_CallShowPDF(0, 'K', 9600, this.textBox1.Text.Trim(), this.textBox2.Text.Trim(), "", "");
  23. //if (ret != 0)
  24. // MessageBox.Show("失败,ret="+ret, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
  25. }
  26. catch (Exception ex)
  27. {
  28. MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
  29. }
  30. }
  31. private double ratio = 1; // 图片的起始显示比例
  32. private double ratioStep = 0.1;
  33. private Size pic_size;
  34. private int xPos;
  35. private int yPos;
  36. private void Form1_Load(object sender, EventArgs e)
  37. {
  38. var bmp = Bitmap.FromFile("f:\\1.jpg");
  39. Size size = bmp.Size;
  40. this.panel1.ClientSize = new Size(this.panel1.ClientSize.Width,
  41. (int)(this.panel1.ClientSize.Width * (size.Height * 1.0f / size.Width)));
  42. this.pictureBox1.Size = this.panel1.ClientSize;
  43. this.pictureBox1.Location = new Point(0, 0);
  44. this.pictureBox1.Image = bmp;
  45. pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
  46. pictureBox1.MouseWheel += new MouseEventHandler(pictureBox1_MouseWheel);
  47. pictureBox1.MouseMove += pictureBox1_MouseMove;
  48. pictureBox1.MouseDown += pictureBox1_MouseDown;
  49. this.ActiveControl = this.pictureBox1; // 设置焦点
  50. pic_size = this.panel1.ClientSize;
  51. //
  52. //MessageBox.Show("菜单栏厚度" + SystemInformation.MenuHeight.ToString()); //获取标准菜单栏的厚度
  53. //MessageBox.Show("标题栏厚度" + SystemInformation.CaptionHeight.ToString()); //获取标准标题栏的厚度
  54. this.Height = panel1.Bottom+ SystemInformation.CaptionHeight + SystemInformation.MenuHeight+ statusStrip1.Height;
  55. }
  56. private void panel1_SizeChanged(object sender, EventArgs e)
  57. {
  58. pic_size = this.panel1.ClientSize;
  59. }
  60. private void pictureBox1_MouseWheel(object sender, MouseEventArgs e)
  61. {
  62. Point pictureBoxPoint = this.PointToClient(Cursor.Position);
  63. //this.Text = $"{e.X}:{e.Y}; {pictureBoxPoint.X}:{pictureBoxPoint.Y}; {pictureBox1.Left}:{pictureBox1.Top}; " +
  64. // $"{this.pictureBox1.Width}:{this.pictureBox1.Height}; {this.Width}:{this.Height}; " +
  65. // $"Cursor:{Cursor.Position.X}:{Cursor.Position.Y}";
  66. if (e.Delta > 0)
  67. {
  68. ratio += ratioStep;
  69. if (ratio > 100) // 放大上限
  70. ratio = 100;
  71. else
  72. {
  73. int x = (int)(pictureBox1.Left-e.X * (e.X * 1.0d / pictureBox1.Width * ratioStep) + 0.5);
  74. int y = (int)(pictureBox1.Top- e.Y * (e.Y * 1.0d / pictureBox1.Height * ratioStep) + 0.5);
  75. //this.Text = $"{pictureBox1.Width}-{pic_size.Width};{ratio},{pictureBox1.Left}-{e.X}* 比例:{e.X*1.0d/pictureBox1.Width}={e.X}/{pictureBox1.Width} * {(ratioStep)}={x} | " +
  76. // $"{pictureBox1.Top}-{e.Y}* {e.Y * 1.0f / pictureBox1.Height * (ratio - 1.0d)}={y}";
  77. this.changePictureBoxSize(new Point(x, y), ratio);
  78. }
  79. }
  80. else if (ratio - ratioStep >= 1)
  81. {
  82. ratio -= ratioStep;
  83. //if (ratio < 0.1) // 放大下限
  84. // ratio = 0.1;
  85. //else
  86. int x = (int)(pictureBox1.Left + e.X * (e.X * 1.0d / pictureBox1.Width * ratioStep) + 0.5);
  87. int y = (int)(pictureBox1.Top + e.Y * (e.Y * 1.0d / pictureBox1.Height * ratioStep) +0.5);
  88. this.changePictureBoxSize(new Point(x, y), ratio);
  89. }
  90. }
  91. private void changePictureBoxSize(Point location, double ratio)
  92. {
  93. var picSize = pictureBox1.Size;
  94. picSize.Width = Convert.ToInt32(pic_size.Width * ratio);
  95. picSize.Height = Convert.ToInt32(pic_size.Height * ratio);
  96. pictureBox1.Size = picSize;
  97. if (location.X > 0) location.X = 0;
  98. if (location.Y > 0) location.Y = 0;
  99. if (picSize.Width+location.X <this.panel1.ClientSize.Width) location.X = -(picSize.Width- this.panel1.ClientSize.Width);
  100. if (picSize.Height + location.Y < this.panel1.ClientSize.Height) location.Y = -(picSize.Height - this.panel1.ClientSize.Height);
  101. //Point location = new Point();
  102. //location.X = (this.ClientSize.Width - this.pictureBox1.Width) / 2;
  103. //location.Y = (this.ClientSize.Height - this.pictureBox1.Height) / 2;
  104. this.pictureBox1.Location = location;
  105. }
  106. private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
  107. {
  108. try
  109. {
  110. // 鼠标按下拖拽图片
  111. if (e.Button == MouseButtons.Left)
  112. {
  113. this.Text = $"{e.X}:{e.Y};{xPos}:{yPos}";
  114. // 限制拖拽出框
  115. if (pictureBox1.Width > this.panel1.ClientSize.Width
  116. || pictureBox1.Height > this.panel1.ClientSize.Height)
  117. {
  118. int moveX = e.X - xPos;
  119. int moveY = e.Y - yPos;
  120. if ((pictureBox1.Left + moveX) <= 0
  121. && (pictureBox1.Top + moveY) <= 0
  122. && (pictureBox1.Right + moveX) >= this.panel1.ClientSize.Width
  123. && (pictureBox1.Bottom + moveY) >= this.panel1.ClientSize.Height)
  124. {
  125. pictureBox1.Left += moveX;//设置x坐标.
  126. pictureBox1.Top += moveY;//设置y坐标.
  127. }
  128. }
  129. }
  130. }
  131. catch (Exception dd)
  132. {
  133. MessageBox.Show(dd.Message);
  134. }
  135. }
  136. private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
  137. {
  138. xPos = e.X;//当前x坐标.
  139. yPos = e.Y;//当前y坐标.
  140. }
  141. //--------------
  142. void pictureBox1_MouseWheel1(object sender, MouseEventArgs e)//鼠标滚轮事件
  143. {
  144. double step = 1.2;//缩放倍率
  145. if (e.Delta > 0)
  146. {
  147. if (pictureBox1.Height >= Screen.PrimaryScreen.Bounds.Height * 10)
  148. return;
  149. pictureBox1.Height = (int)(pictureBox1.Height * step);
  150. pictureBox1.Width = (int)(pictureBox1.Width * step);
  151. int px = Cursor.Position.X - pictureBox1.Location.X;
  152. int py = Cursor.Position.Y - pictureBox1.Location.Y;
  153. int px_add = (int)(px * (step - 1.0));
  154. int py_add = (int)(py * (step - 1.0));
  155. pictureBox1.Location = new Point(pictureBox1.Location.X - px_add, pictureBox1.Location.Y - py_add);
  156. Application.DoEvents();
  157. }
  158. else
  159. {
  160. if (pictureBox1.Height <= Screen.PrimaryScreen.Bounds.Height) return;
  161. pictureBox1.Height = (int)(pictureBox1.Height / step);
  162. pictureBox1.Width = (int)(pictureBox1.Width / step);
  163. int px = Cursor.Position.X - pictureBox1.Location.X;
  164. int py = Cursor.Position.Y - pictureBox1.Location.Y;
  165. int px_add = (int)(px * (1.0 - 1.0 / step));
  166. int py_add = (int)(py * (1.0 - 1.0 / step));
  167. pictureBox1.Location = new Point(pictureBox1.Location.X + px_add, pictureBox1.Location.Y + py_add);
  168. Application.DoEvents();
  169. }
  170. }
  171. private void tsbtnClose_Click(object sender, EventArgs e)
  172. {
  173. this.checkBox1.Checked = !this.checkBox1.Checked;
  174. //this.panel1.Width *= 2;
  175. //this.panel1.Height *= 2;
  176. }
  177. private void checkBox1_CheckedChanged(object sender, EventArgs e)
  178. {
  179. this.Text=this.checkBox1.Checked.ToString();
  180. }
  181. private void tsbtnMakeTag_Click(object sender, EventArgs e)
  182. {
  183. }
  184. }
  185. }