private void pictureBox1_MouseMove(object sender, MouseEventArgs e) { if (_bDrawing == true) { return; } if (e.Button == MouseButtons.None) { label1.Text = "X=" + e.X + " Y=" + e.Y + " Pixel Value=" + " " + _imageBitMap.GetPixel(e.X, e.Y); } else { if ((e.Button == MouseButtons.Left) && (_xLeft > -1) && (_yUp > -1)) { // Create pen. _graphicState = _graphic.Save(); pictureBox1.Image = (Image)_imageBitMap; // Draw rectangle to screen. _Rectangle._second._nX = e.X; _Rectangle._second._nY = e.Y; _Rectangle.Draw(_graphic, Color.Green, new Pen(Color.Green, 5)); label1.Text = "Draw Rectangle: X1 = " + Convert.ToString(_Rectangle._first._nX) + ", Y1 = " + Convert.ToString(_Rectangle._first._nY) + ", X2 = " + Convert.ToString(e.X) + ", Y2 = " + Convert.ToString(e.Y); } } }
private void pictureBoxMain_MouseClick(object sender, MouseEventArgs e) { // Only left button can be used if (e.Button != MouseButtons.Left) { // Check if right button has been pressed if (e.Button == MouseButtons.Right) { if (_nNumMouseSingleClick >= 1) { switch (_currentObject) { case EOBJECT_DRAW.ELINE_OBJECT: _Line._second._nX = e.X; _Line._second._nY = e.Y; _Line.Draw(_Graphics, Color.White); break; case EOBJECT_DRAW.ERECTANGLE_BORDER_OBJECT: _Rectangle._second._nX = e.X; _Rectangle._second._nY = e.Y; _Rectangle.Draw(_Graphics, Color.White); break; case EOBJECT_DRAW.ERECTANGLE_FILLER_OBJECT: _RectangleFiller._second._nX = e.X; _RectangleFiller._second._nY = e.Y; _RectangleFiller.Draw(_Graphics, Color.White); break; case EOBJECT_DRAW.ECIRCLE_OBJECT: _Circle._nRange = Math.Max(Math.Abs(_Circle._nCenterX - e.X), Math.Abs(_Circle._nCenterY - e.Y)); _Circle.Draw(_Graphics, Color.White); break; } ResetCurrentActionLabel(); _currentObject = EOBJECT_DRAW.EUNDEFINED_OBJECT; } else { _mouseSingleClickDown._nX = e.X; _mouseSingleClickDown._nY = e.Y; contextMenuStrip1.Show(Cursor.Position.X, Cursor.Position.Y); } } return; } _nNumMouseSingleClick++; _mouseSingleClickDown._nX = e.X; _mouseSingleClickDown._nY = e.Y; // Look action to do switch (_currentObject) { case EOBJECT_DRAW.ELINE_OBJECT: if (_nNumMouseSingleClick == 1) { _Line._first._nX = e.X; _Line._first._nY = e.Y; ShowCurrentActionLabel("Draw Line: X1 = " + Convert.ToString(_Line._first._nX) + ", Y1 = " + Convert.ToString(_Line._first._nY)); } else if (_nNumMouseSingleClick == 2) { _Line._second._nX = e.X; _Line._second._nY = e.Y; _Line.Draw(_Graphics); // Add element _Container.AddLine(_Line, treeViewObjects); ResetCurrentActionLabel(); _currentObject = EOBJECT_DRAW.EUNDEFINED_OBJECT; } break; case EOBJECT_DRAW.ERECTANGLE_BORDER_OBJECT: if (_nNumMouseSingleClick == 1) { _Rectangle._first._nX = e.X; _Rectangle._first._nY = e.Y; ShowCurrentActionLabel("Draw Rectangle: X1 = " + Convert.ToString(_Rectangle._first._nX) + ", Y1 = " + Convert.ToString(_Rectangle._first._nY)); } else if (_nNumMouseSingleClick == 2) { _Rectangle._second._nX = e.X; _Rectangle._second._nY = e.Y; _Rectangle.Draw(_Graphics); // Add element _Container.AddRectangle(_Rectangle, treeViewObjects); ResetCurrentActionLabel(); _currentObject = EOBJECT_DRAW.EUNDEFINED_OBJECT; } break; case EOBJECT_DRAW.ERECTANGLE_FILLER_OBJECT: if (_nNumMouseSingleClick == 1) { _RectangleFiller._first._nX = e.X; _RectangleFiller._first._nY = e.Y; ShowCurrentActionLabel("Fill Rectangle: X1 = " + Convert.ToString(_RectangleFiller._first._nX) + ", Y1 = " + Convert.ToString(_RectangleFiller._first._nY)); } else if (_nNumMouseSingleClick == 2) { _RectangleFiller._second._nX = e.X; _RectangleFiller._second._nY = e.Y; _RectangleFiller.Draw(_Graphics); // Add element _Container.AddRectangleFill(_RectangleFiller, treeViewObjects); ResetCurrentActionLabel(); _currentObject = EOBJECT_DRAW.EUNDEFINED_OBJECT; } break; case EOBJECT_DRAW.ECIRCLE_OBJECT: if (_nNumMouseSingleClick == 1) { _Circle._nCenterX = e.X; _Circle._nCenterY = e.Y; if (_Circle._bIsFill == false) { ShowCurrentActionLabel("Draw Circle: Center X = " + Convert.ToString(_Circle._nCenterX) + ", Center Y = " + Convert.ToString(_Circle._nCenterY)); } else { ShowCurrentActionLabel("Fill Circle: Center X = " + Convert.ToString(_Circle._nCenterX) + ", Center Y = " + Convert.ToString(_Circle._nCenterY)); } } else if (_nNumMouseSingleClick == 2) { _Circle._nRange = Math.Max(Math.Abs(_Circle._nCenterX - e.X), Math.Abs(_Circle._nCenterY - e.Y)); _Circle.Draw(_Graphics); // Add element _Container.AddCircle(_Circle, treeViewObjects); ResetCurrentActionLabel(); _currentObject = EOBJECT_DRAW.EUNDEFINED_OBJECT; } break; } }