123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using PaintDotNet.Base.SettingModel;
- using TUCamera;
- using TUCAMAPI;
- using System.Runtime.InteropServices;
- namespace PaintDotNet.ImageCollect.CameraComponent
- {
- public partial class FrameCameraSetControl : UserControl
- {
- private TUCamera.TUCamera m_camera;
- private CameraParamModel m_cameraParamModel;
- private bool m_use;
- private Point m_startP; //鼠标按下时坐标
- private bool m_blnDraw = false;
- private Rectangle m_rect;//初始设置一个拖拽的显示框
- private SolidBrush m_brush = new SolidBrush(Color.Black);
- private int m_handle = 0;
- private int m_targetX = 0; // 起始点X坐标 对应分辨率
- private int m_targetY = 0; // 起始点Y坐标 对应分辨率
- private int m_targetWidth = 320; //显示框的宽度 对应分辨率
- private int m_targetHeight = 200; //显示框的高度 对应分辨率
- private int m_tempX = 0;
- private int m_tempY = 0;
- private int m_tempW = 0;
- private int m_tempH = 0;
- private TUCameraIFrameProcess m_process = null;
- private Size m_resolution; // 分辨率
- private bool m_isWaiting;
- private void InitializeLanguageText()
- {
- this.groupBox3.Text = PdnResources.GetString("Menu.Setting.Text");
- this.quanfuButton.Text = PdnResources.GetString("Menu.Fullframe.text");
- this.zhongxinButton.Text = PdnResources.GetString("Menu.center.text");
- this.label4.Text = PdnResources.GetString("Menu.Imagesize.text") + ":";
- this.label1.Text = PdnResources.GetString("Menu.Startingcoordinates.text") + ":";
- this.shuaxinButton.Text = PdnResources.GetString("Menu.Refreshthumbnail.text");
- this.groupBox2.Text = PdnResources.GetString("Menu.Resolution.text");
- }
- public FrameCameraSetControl(CameraParamModel model, bool use)
- {
- InitializeComponent();
- InitializeLanguageText();
- m_use = use;
- m_camera = TUCameraManager.GetInstance().GetCurrentCamera();
- m_cameraParamModel = model;
-
- InitializeControlData();
- //InitializeData();
- }
- public void ReLoad(CameraParamModel model, bool use)
- {
- m_cameraParamModel = model;
- m_use = use;
- InitializeControlData();
- InitializeData();
- }
- private void InitializeControlData()
- {
- cmbResolution.Items.Clear();
- List<string> resolutions = this.m_camera.GetResolutionRange();
- for (int i = 0; i < resolutions.Count; i++)
- {
- cmbResolution.Items.Add(resolutions[i]);
- }
- if (resolutions.Count > 0)
- {
- cmbResolution.SelectedIndex = m_cameraParamModel.parame.Resolution;
- }
-
- //
- this.zuobiaoXTextBox.Text = m_cameraParamModel.parame.previewRectX.ToString();
- this.zuobiaoYTextBox.Text = m_cameraParamModel.parame.previewRectY.ToString();
- this.chicunWTextBox.Text = m_cameraParamModel.parame.previewRectW.ToString();
- this.chicunHTextBox.Text = m_cameraParamModel.parame.previewRectH.ToString();
- }
- /// <summary>
- /// 绑定样式数据
- /// </summary>
- private void InitializeData()
- {
- m_targetX = this.m_cameraParamModel.parame.previewRectX;
- m_targetY = this.m_cameraParamModel.parame.previewRectY;
- m_targetWidth = this.m_cameraParamModel.parame.previewRectW;
- m_targetHeight = this.m_cameraParamModel.parame.previewRectH;
- SetROI();
- m_rect = new Rectangle();
- drawingImg();
- if (m_resolution.Width > 0 && m_resolution.Height > 0)
- {
- this.pictureBox1.Height = (this.pictureBox1.Width * m_resolution.Height) / m_resolution.Width;
- m_rect.X = this.m_cameraParamModel.parame.previewRectX * this.pictureBox1.Width / m_resolution.Width;
- m_rect.Y = this.m_cameraParamModel.parame.previewRectY * this.pictureBox1.Height / m_resolution.Height;
- m_rect.Width = this.m_cameraParamModel.parame.previewRectW * this.pictureBox1.Width / m_resolution.Width;
- m_rect.Height = this.m_cameraParamModel.parame.previewRectH * this.pictureBox1.Height / m_resolution.Height;
- }
- else
- {
- m_resolution.Width = pictureBox1.Width;
- m_resolution.Height = pictureBox1.Height;
- m_rect.X = 0;
- m_rect.Y = 0;
- m_rect.Width = this.pictureBox1.Width;
- m_rect.Height = this.pictureBox1.Height;
- }
- }
- private void zhongxinButton_Click(object sender, EventArgs e)
- {
- if (zhongxinButton.Text.Equals(PdnResources.GetString("Menu.center.text")))
- {
- zhongxinButton.Text = PdnResources.GetString("Menu.Start.text");
- int X = pictureBox1.Width / 2 - m_rect.Width / 2;
- int Y = pictureBox1.Height / 2 - m_rect.Height / 2;
- m_rect.X = X;
- m_rect.Y = Y;
- m_targetX = m_rect.X * m_resolution.Width / this.pictureBox1.Width;
- m_targetY = m_rect.Y * m_resolution.Height / this.pictureBox1.Height;
- }
- else
- {
- zhongxinButton.Text = PdnResources.GetString("Menu.center.text");
- int X = 0;
- int Y = 0;
- m_rect.X = X;
- m_rect.Y = Y;
- m_targetX = m_rect.X * m_resolution.Width / this.pictureBox1.Width;
- m_targetY = m_rect.Y * m_resolution.Height / this.pictureBox1.Height;
- }
- SetROI();
- this.pictureBox1.Refresh();
- }
- private void quanfuButton_Click(object sender, EventArgs e)
- {
- if (this.quanfuButton.Text.Equals(PdnResources.GetString("Menu.Lasttime.text")))
- {
- this.quanfuButton.Text = PdnResources.GetString("Menu.Fullframe.text");
- if (m_resolution.Width>0 && m_resolution.Height>0)
- {
- m_rect.X = m_tempX * this.pictureBox1.Width / m_resolution.Width;
- m_rect.Y = m_tempY * this.pictureBox1.Height / m_resolution.Height;
- m_rect.Width = m_tempW * this.pictureBox1.Width / m_resolution.Width;
- m_rect.Height = m_tempH * this.pictureBox1.Height / m_resolution.Height;
- m_targetX = m_tempX;
- m_targetY = m_tempY;
- m_targetWidth = m_tempW;
- m_targetHeight = m_tempH;
- }
- }
- else
- {
- this.quanfuButton.Text = PdnResources.GetString("Menu.Lasttime.text");
- m_tempX = m_targetX;
- m_tempY = m_targetY;
- m_tempW = m_targetWidth;
- m_tempH = m_targetHeight;
- int X = 0;
- int Y = 0;
- m_rect.X = X;
- m_rect.Y = Y;
- m_rect.Width = this.pictureBox1.Width;
- m_rect.Height = this.pictureBox1.Height;
- m_targetX = 0;
- m_targetY = 0;
- m_targetWidth = m_resolution.Width;
- m_targetHeight = m_resolution.Height;
- }
- SetROI();
- this.pictureBox1.Refresh();
- }
- private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
- {
- m_handle = HitTest(e.Location);
- if (m_handle < 0)
- {
- if (m_rect.Contains(e.Location))//判断鼠标按下的坐标是否在红框中,确定是否拖动的红框
- {
- m_handle = 9;
- }
- }
- this.Cursor = GetHandleCursor(m_handle);
- m_startP = e.Location;
- Invalidate();
- m_blnDraw = true;
- }
- private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
- {
- if (m_handle > 0 && m_blnDraw)
- {
- if (e.Button != MouseButtons.Left)//判断是否按下左键
- return;
- MoveHandleTo(e.Location, m_handle);
- }
- }
- private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
- {
- m_blnDraw = false; //结束绘制
- this.Cursor = Cursors.Default;
- SetROI();
- this.pictureBox1.Refresh();
- }
- public Rectangle GetHandleRectangle(int handleNumber)
- {
- Point point = GetHandle(handleNumber);
- return new Rectangle(point.X - 4, point.Y - 4, 8, 8);
- }
- public int HitTest(Point point)
- {
- for (int i = 1; i <= 8; i++)
- {
- if (GetHandleRectangle(i).Contains(point))
- return i;
- }
- return -1;
- }
- public Point GetHandle(int handleNumber)
- {
- int x, y, xCenter, yCenter;
- xCenter = m_rect.X + m_rect.Width / 2;
- yCenter = m_rect.Y + m_rect.Height / 2;
- x = m_rect.X;
- y = m_rect.Y;
- switch (handleNumber)
- {
- case 1:
- x = m_rect.X;
- y = m_rect.Y;
- break;
- case 2:
- x = xCenter;
- y = m_rect.Y;
- break;
- case 3:
- x = m_rect.Right;
- y = m_rect.Y;
- break;
- case 4:
- x = m_rect.Right;
- y = yCenter;
- break;
- case 5:
- x = m_rect.Right;
- y = m_rect.Bottom;
- break;
- case 6:
- x = xCenter;
- y = m_rect.Bottom;
- break;
- case 7:
- x = m_rect.X;
- y = m_rect.Bottom;
- break;
- case 8:
- x = m_rect.X;
- y = yCenter;
- break;
- }
- return new Point(x, y);
- }
- public Cursor GetHandleCursor(int handleNumber)
- {
- switch (handleNumber)
- {
- case 1:
- return Cursors.SizeNWSE;
- case 2:
- return Cursors.SizeNS;
- case 3:
- return Cursors.SizeNESW;
- case 4:
- return Cursors.SizeWE;
- case 5:
- return Cursors.SizeNWSE;
- case 6:
- return Cursors.SizeNS;
- case 7:
- return Cursors.SizeNESW;
- case 8:
- return Cursors.SizeWE;
- default:
- return Cursors.Default;
- }
- }
- public void MoveHandleTo(Point point, int handleNumber)
- {
- if (point.X > pictureBox1.Width)
- {
- point.X = pictureBox1.Width;
- }
- if (point.X < 0)
- {
- point.X = 0;
- }
- if (point.Y < 0)
- {
- point.Y = 0;
- }
- if (point.Y > pictureBox1.Height)
- {
- point.Y = pictureBox1.Height;
- }
- int left = m_rect.Left;
- int top = m_rect.Top;
- int right = m_rect.Right;
- int bottom = m_rect.Bottom;
- switch (handleNumber)
- {
- case 1:
- left = point.X;
- top = point.Y;
- break;
- case 2:
- top = point.Y;
- break;
- case 3:
- right = point.X;
- top = point.Y;
- break;
- case 4:
- right = point.X;
- break;
- case 5:
- right = point.X;
- bottom = point.Y;
- break;
- case 6:
- bottom = point.Y;
- break;
- case 7:
- left = point.X;
- bottom = point.Y;
- break;
- case 8:
- left = point.X;
- break;
- case 9:
- left = m_rect.Left +(point.X - m_startP.X);
- top = m_rect.Top + (point.Y - m_startP.Y);
- //判断是否超过左上角
- if (left < 0)
- left = 0;
- if (top < 0)
- top = 0;
- //判断是否超过右下 角
- if (left > (pictureBox1.Width - m_rect.Width))
- left = pictureBox1.Width - m_rect.Width;
- if (top > (pictureBox1.Height - m_rect.Height))
- top = pictureBox1.Height - m_rect.Height;
- right = left + m_rect.Width;
- bottom = top + m_rect.Height;
- break;
- }
- m_rect.X = left;
- m_rect.Y = top;
- m_rect.Width = right - left;
- m_rect.Height = bottom - top;
- m_targetX = m_rect.X * m_resolution.Width / this.pictureBox1.Width;
- m_targetY = m_rect.Y * m_resolution.Height / this.pictureBox1.Height;
- m_targetWidth = m_rect.Width * m_resolution.Width / this.pictureBox1.Width;
- m_targetHeight = m_rect.Height * m_resolution.Height / this.pictureBox1.Height;
- pictureBox1.Refresh();
- m_startP = point;
- }
-
- private void drawingImg()
- {
- if (!m_camera.IsOpen())
- {
- return;
- }
- m_isWaiting = true;
- int resolution_width = pictureBox1.Width;
- int resolution_height = pictureBox1.Height;
- Console.WriteLine("点击刷新缩略图");
- if (m_camera.IsOpen()) {
- m_camera.m_drawAllHandler += new DrawAllHandler(CallbackDraw);
- m_camera.StartWaitForFrame();
- m_process = m_camera.StartDrawing(ref resolution_width, ref resolution_height);
- }
- m_resolution.Width = resolution_width;
- m_resolution.Height = resolution_height;
- if (resolution_width == 0 || resolution_height == 0)
- {
- m_resolution.Width = pictureBox1.Width;
- m_resolution.Height = pictureBox1.Height;
- }
- }
- private byte[] m_pbuf;
- /// <summary>
- /// 绘制
- /// </summary>
- /// <param name="pBuf"></param>
- /// <param name="obj"></param>
- public void CallbackDraw(byte[] pBuf, object obj, int channel)
- {
- lock (obj)
- {
- try
- {
- m_isWaiting = false;
- Console.WriteLine("接收全图buf");
- m_camera.m_drawAllHandler -= new DrawAllHandler(CallbackDraw);
- OpenCvSharp.Mat mat;
- if (channel == 1)
- {
- mat = new OpenCvSharp.Mat(m_resolution.Height, m_resolution.Width, OpenCvSharp.MatType.CV_8UC1, pBuf);
- }
- else
- {
- mat = new OpenCvSharp.Mat(m_resolution.Height, m_resolution.Width, OpenCvSharp.MatType.CV_8UC3, pBuf);
- }
- OpenCvSharp.Cv2.Flip(mat, mat, 0);
- this.pictureBox1.Image = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat);
- stopDrawing();
- if (mat != null)
- {
- mat.Dispose();
- }
- GC.Collect();
- }
- catch (Exception)
- {
- }
-
- }
- }
- public void CallMaxDraw(Bitmap bitmap)
- {
- m_camera.m_bufHandler -= CallMaxDraw;
- this.pictureBox1.Image = bitmap;
- }
- private void stopDrawing()
- {
- //创建一个委托,用于封装一个方法,在这里是封装了 控制更新控件 的方法
- Action invokeAction = new Action(stopDrawing);
- //判断操作控件的线程是否创建控件的线程
- //调用方调用方位于创建控件所在的线程以外的线程中,如果在其他线程则对控件进行方法调用时必须调用 Invoke 方法
- if (this.InvokeRequired)
- {
- //与调用线程不同的线程上创建(说明您必须通过 Invoke 方法对控件进行调用)
- this.Invoke(invokeAction);
- }
- else
- {
- m_camera.StopDrawing(m_process);
- m_camera.StopWaitForFrame();
- //窗体线程,即主线程
- shuaxinButton.Enabled = true;
- }
- }
- private void shuaxinButton_Click(object sender, EventArgs e)
- {
- drawingImg();
- shuaxinButton.Enabled = false;
- }
- private void pictureBox1_Paint(object sender, PaintEventArgs e)
- {
- if (m_isWaiting)
- {
- return;
- }
- if (m_rect.Width != pictureBox1.Width || m_rect.Height != pictureBox1.Height)
- {
- this.quanfuButton.Text = PdnResources.GetString("Menu.Fullframe.text");
- }
- this.m_cameraParamModel.parame.previewRectX = m_targetX;
- this.m_cameraParamModel.parame.previewRectY = m_targetY;
- this.m_cameraParamModel.parame.previewRectW = m_targetWidth;
- this.m_cameraParamModel.parame.previewRectH = m_targetHeight;
-
- if (m_resolution.Width != 0 && m_resolution.Height != 0)
- {
- if (m_rect.Width > 0 && m_rect.Height > 0)
- {
- e.Graphics.DrawRectangle(new Pen(Color.Red, 2), m_rect);//重新绘制颜色为红色
- for (int i = 1; i <= 8; i++)
- {
- e.Graphics.FillRectangle(m_brush, GetHandleRectangle(i));
- }
- }
- }
- this.zuobiaoXTextBox.Text = m_targetX.ToString();
- this.zuobiaoYTextBox.Text = m_targetY.ToString();
- this.chicunWTextBox.Text = m_targetWidth.ToString();
- this.chicunHTextBox.Text = m_targetHeight.ToString();
- }
- private void zuobiaoXTextBox_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (e.KeyChar == (char)Keys.Enter)
- {
- int val = Convert.ToInt32(this.zuobiaoXTextBox.Text);
- if (val < 0)
- {
- this.zuobiaoXTextBox.Text = "0";
- }
- else if ((val + m_targetWidth) > m_resolution.Width)
- {
- zuobiaoXTextBox.Text = (m_resolution.Width - m_targetWidth).ToString();
- }
- TextChange();
- }
- if (e.KeyChar != 8 && !Char.IsDigit(e.KeyChar))
- {
- e.Handled = true;
- }
- }
- private void zuobiaoYTextBox_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (e.KeyChar == (char)Keys.Enter)
- {
- int val = Convert.ToInt32(this.zuobiaoYTextBox.Text);
- if (val < 0)
- {
- this.zuobiaoYTextBox.Text = "0";
- }
- else if ((val + m_targetHeight) > m_resolution.Height)
- {
- this.zuobiaoYTextBox.Text = (m_resolution.Height - m_targetHeight).ToString();
- }
- TextChange();
- }
- if (e.KeyChar != 8 && !Char.IsDigit(e.KeyChar))
- {
- e.Handled = true;
- }
- }
- private void chicunWTextBox_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (e.KeyChar == (char)Keys.Enter)
- {
- int val = Convert.ToInt32(this.chicunWTextBox.Text);
- if (val < 0)
- {
- this.chicunWTextBox.Text = "1";
- }
- else if ((val + Convert.ToInt32(this.zuobiaoXTextBox.Text)) > m_resolution.Width)
- {
- this.chicunWTextBox.Text = (m_resolution.Width - Convert.ToInt32(this.zuobiaoXTextBox.Text)).ToString();
- }
- TextChange();
- }
- if (e.KeyChar != 8 && !Char.IsDigit(e.KeyChar))
- {
- e.Handled = true;
- }
- }
- private void chicunHTextBox_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (e.KeyChar == (char)Keys.Enter)
- {
- int val = Convert.ToInt32(this.chicunHTextBox.Text);
- if (val < 0)
- {
- this.chicunHTextBox.Text = "1";
- }
- else if ((val + Convert.ToInt32(this.zuobiaoYTextBox.Text)) > m_resolution.Height)
- {
- this.chicunHTextBox.Text = (m_resolution.Height - Convert.ToInt32(this.zuobiaoYTextBox.Text)).ToString();
- }
- TextChange();
- }
- if (e.KeyChar != 8 && !Char.IsDigit(e.KeyChar))
- {
- e.Handled = true;
- }
- }
- private void TextChange()
- {
- m_targetX = Convert.ToInt32(this.zuobiaoXTextBox.Text);
- m_targetY = Convert.ToInt32(this.zuobiaoYTextBox.Text);
- m_targetWidth = Convert.ToInt32(this.chicunWTextBox.Text);
- m_targetHeight = Convert.ToInt32(this.chicunHTextBox.Text);
- if (m_resolution.Width > 0 && m_resolution.Height > 0)
- {
- m_rect.X = m_targetX * this.pictureBox1.Width / m_resolution.Width;
- m_rect.Y = m_targetY * this.pictureBox1.Height / m_resolution.Height;
- m_rect.Width = m_targetWidth * this.pictureBox1.Width / m_resolution.Width;
- m_rect.Height = m_targetHeight * this.pictureBox1.Height / m_resolution.Height;
- }
- else
- {
- m_rect.X = m_targetX;
- m_rect.Y = m_targetY;
- m_rect.Width = m_targetWidth;
- m_rect.Height = m_targetHeight;
- }
- SetROI();
- this.pictureBox1.Refresh();
- }
- private void SetROI()
- {
- if (m_use)
- {
- m_camera.SetROI(ref m_targetX, ref m_targetY, ref m_targetWidth, ref m_targetHeight);
- this.m_cameraParamModel.parame.previewRectX = m_targetX;
- this.m_cameraParamModel.parame.previewRectY = m_targetY;
- this.m_cameraParamModel.parame.previewRectW = m_targetWidth;
- this.m_cameraParamModel.parame.previewRectH = m_targetHeight;
- }
- }
- private void cmbResolution_SelectedIndexChanged(object sender, EventArgs e)
- {
- m_cameraParamModel.parame.Resolution = cmbResolution.SelectedIndex;
- int resolutionId = m_camera.GetResolutionId();
- if (resolutionId != m_cameraParamModel.parame.Resolution)
- {
- // 分辨率
- m_camera.SetResolution(m_cameraParamModel.parame.Resolution);
- //m_camera.m_bufHandler += new BufHandler(CallMaxDraw);
- }
- m_camera.GetROI(ref m_cameraParamModel.parame.previewRectX, ref m_cameraParamModel.parame.previewRectY, ref m_cameraParamModel.parame.previewRectW, ref m_cameraParamModel.parame.previewRectH);
- InitializeData();
- this.zuobiaoXTextBox.Text = m_cameraParamModel.parame.previewRectX.ToString();
- this.zuobiaoYTextBox.Text = m_cameraParamModel.parame.previewRectY.ToString();
- this.chicunWTextBox.Text = m_cameraParamModel.parame.previewRectW.ToString();
- this.chicunHTextBox.Text = m_cameraParamModel.parame.previewRectH.ToString();
- }
- private void chicunHTextBox_Leave(object sender, EventArgs e)
- {
- int val = Convert.ToInt32(this.chicunHTextBox.Text);
- if (val < 0)
- {
- this.chicunHTextBox.Text = "1";
- }
- else if ((val + Convert.ToInt32(this.zuobiaoYTextBox.Text)) > m_resolution.Height)
- {
- this.chicunHTextBox.Text = (m_resolution.Height - Convert.ToInt32(this.zuobiaoYTextBox.Text)).ToString();
- }
- TextChange();
- }
- private void chicunWTextBox_Leave(object sender, EventArgs e)
- {
- int val = Convert.ToInt32(this.chicunWTextBox.Text);
- if (val < 0)
- {
- this.chicunWTextBox.Text = "1";
- }
- else if ((val + Convert.ToInt32(this.zuobiaoXTextBox.Text)) > m_resolution.Width)
- {
- this.chicunWTextBox.Text = (m_resolution.Width - Convert.ToInt32(this.zuobiaoXTextBox.Text)).ToString();
- }
- TextChange();
- }
- private void zuobiaoYTextBox_Leave(object sender, EventArgs e)
- {
- int val = Convert.ToInt32(this.zuobiaoYTextBox.Text);
- if (val < 0)
- {
- this.zuobiaoYTextBox.Text = "0";
- }
- else if ((val + m_targetHeight) > m_resolution.Height)
- {
- this.zuobiaoYTextBox.Text = (m_resolution.Height - m_targetHeight).ToString();
- }
- TextChange();
- }
- private void zuobiaoXTextBox_Leave(object sender, EventArgs e)
- {
- int val = Convert.ToInt32(this.zuobiaoXTextBox.Text);
- if (val < 0)
- {
- this.zuobiaoXTextBox.Text = "0";
- }
- else if ((val + m_targetWidth) > m_resolution.Width)
- {
- zuobiaoXTextBox.Text = (m_resolution.Width - m_targetWidth).ToString();
- }
- TextChange();
- }
- }
- }
|