Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #region ViewJob
- public class ViewJob
- {
- private Rectangle m_rectRubberBand;
- private Point m_pntPointOne;
- private Point m_pntPointTwo;
- private Pen m_penRubberBandPen;
- private Rectangle m_rectOldRubberBand;
- //Constructor
- public KofaxViewJob()
- {
- //Create the default pen
- m_penRubberBandPen = new Pen(Color.Red, 1);
- m_penRubberBandPen.DashCap = System.Drawing.Drawing2D.DashCap.Round;
- m_penRubberBandPen.DashPattern = new float[] { 2f, 2f, 2f, 2f };
- }
- //RubberBand
- public Rectangle RubberBand
- {
- get
- {
- return m_rectRubberBand;
- }
- set
- {
- m_rectRubberBand = value;
- }
- }
- //PointOne
- public Point PointOne
- {
- get
- {
- return m_pntPointOne;
- }
- set
- {
- m_pntPointOne = value;
- }
- }
- //PointTwo
- public Point PointTwo
- {
- get
- {
- return m_pntPointTwo;
- }
- set
- {
- m_pntPointTwo = value;
- }
- }
- //RubberBandPen
- public Pen RubberBandPen
- {
- get
- {
- return m_penRubberBandPen;
- }
- set
- {
- m_penRubberBandPen = value;
- }
- }
- //OldRubberBand
- public Rectangle OldRubberBand
- {
- get
- {
- return m_rectOldRubberBand;
- }
- set
- {
- m_rectOldRubberBand = value;
- }
- }
- }
- #endregion
- public partial class MainGUI : Form
- {
- private ViewJob kViewJob = new ViewJob();
- private void pbDisplay_MouseDown(object sender, MouseEventArgs e)
- {
- if (e.Button == System.Windows.Forms.MouseButtons.Right)
- {
- if (kViewJob.RubberBand.IsEmpty)
- {
- kViewJob.PointOne = new Point(e.X, e.Y);
- }
- }
- }
- private void pbDisplay_MouseMove(object sender, MouseEventArgs e)
- {
- if (!kViewJob.PointOne.IsEmpty && kViewJob.PointTwo.IsEmpty)
- {
- Rectangle rectValidArea = new Rectangle(0, 0, pbDisplay.ClientSize.Width, pbDisplay.ClientSize.Height);
- Point pntMouse = new Point(e.X, e.Y);
- if (rectValidArea.Contains(pntMouse))
- {
- Point pntTemp1 = new Point(Math.Min(kViewJob.PointOne.X, e.X), Math.Min(kViewJob.PointOne.Y, e.Y));
- Point pntTemp2 = new Point(Math.Max(kViewJob.PointOne.X, e.X), Math.Max(kViewJob.PointOne.Y, e.Y));
- kViewJob.RubberBand = new Rectangle(pntTemp1.X, pntTemp1.Y, pntTemp2.X - pntTemp1.X, pntTemp2.Y - pntTemp1.Y);
- }
- else
- {
- Point pntInBounds = pntMouse;
- pntInBounds = new Point(Math.Max(pntInBounds.X, 0), Math.Max(pntInBounds.Y, 0));
- pntInBounds = new Point(Math.Min(pntInBounds.X, rectValidArea.Width), Math.Min(pntInBounds.Y, rectValidArea.Height));
- Point pntTemp1 = new Point(Math.Min(kViewJob.PointOne.X, pntInBounds.X), Math.Min(kViewJob.PointOne.Y, pntInBounds.Y));
- Point pntTemp2 = new Point(Math.Max(kViewJob.PointOne.X, pntInBounds.X), Math.Max(kViewJob.PointOne.Y, pntInBounds.Y));
- kViewJob.RubberBand = new Rectangle(pntTemp1.X, pntTemp1.Y, pntTemp2.X - pntTemp1.X - 1, pntTemp2.Y - pntTemp1.Y - 1);
- }
- //Show the rubberband on the picturebox
- pbDisplay.Invalidate();
- }
- }
- private void pbDisplay_MouseUp(object sender, MouseEventArgs e)
- {
- if (!kViewJob.PointOne.IsEmpty && kViewJob.PointTwo.IsEmpty)
- {
- kViewJob.PointTwo = new Point(e.X, e.Y);
- //Get the drawing area of the rubberband
- Rectangle rectAreaToClean = new Rectangle(
- kViewJob.RubberBand.X - (int)(kViewJob.RubberBandPen.Width / 2),
- kViewJob.RubberBand.Y - (int)(kViewJob.RubberBandPen.Width / 2),
- kViewJob.RubberBand.Width + (int)kViewJob.RubberBandPen.Width,
- kViewJob.RubberBand.Height + (int)kViewJob.RubberBandPen.Width);
- //Save the rubberband then clear it
- kViewJob.OldRubberBand = kViewJob.RubberBand;
- kViewJob.PointOne = default(Point);
- kViewJob.PointTwo = default(Point);
- kViewJob.RubberBand = default(Rectangle);
- //Erase the rubberband from the picturebox
- pbDisplay.Invalidate(rectAreaToClean);
- }
- }
- private void pbDisplay_Paint(object sender, PaintEventArgs e)
- {
- if (!kViewJob.RubberBand.IsEmpty)
- {
- e.Graphics.DrawRectangle(kViewJob.RubberBandPen, kViewJob.RubberBand);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement