示例#1
0
        private void buttonClear_Click(object sender, EventArgs e)
        {
            DialogResult confirmDialog = MessageBox.Show("Are you sure you want to clear the image?", "Clearing the Image", MessageBoxButtons.YesNo);

            if (confirmDialog == DialogResult.Yes)
            {
                // clearing all drawings and loaded image
                list.Clear();
                panelMain.BackgroundImage = null;

                this.tmpEllipse = null;
                this.tmpLine = null;
                this.tmpRectangle = null;

                panelMain.Invalidate();
            }
        }
示例#2
0
        private void panelMain_MouseUp(object sender, MouseEventArgs e)
        {
            if (this.mouseDown == true)
            {
                // clearing the cursor information text box
                toolStripStatusLabelCoordinates.Text = "";

                this.mouseDown = false;

                // adding created line to the list
                if (radioButtonLine.Checked == true)
                {
                    this.tmpLine.Pen = this.pen;
                    list.Add(this.tmpLine);
                    this.tmpLine = null;
                }

                // adding created rectangle to the list
                if (radioButtonRectangle.Checked == true)
                {
                    this.tmpRectangle.Pen = this.pen;
                    this.tmpRectangle.Fill = this.fillColour;
                    list.Add(this.tmpRectangle);
                    this.tmpRectangle = null;
                }

                // adding created ellipse to the list
                if (radioButtonEllipse.Checked == true)
                {
                    this.tmpEllipse.Pen = this.pen;
                    this.tmpEllipse.Fill = this.fillColour;
                    list.Add(this.tmpEllipse);
                    this.tmpEllipse = null;
                }

                panelMain.Invalidate();
            }
        }
示例#3
0
        /// <summary>
        /// Opening a new file ensure object passed is new and using a try statement
        /// we will try to open the file. If the test pass then it will try to read the file 
        /// and put the data from file into data members ( DtawObjects class).
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="drawObjectHistory"></param>
        /// <returns>status</returns>
        public static bool OpenSETPaintFile(string filename, List<DrawObject> drawObjectHistory)
        {
            BinaryReader openFile;
             byte tempByte = 0;
             DrawObject drawObject = new DrawObject();
             bool status = true;

             drawObjectHistory.Clear();   /*opening a new file ensure object passed is new*/

             try
             {
            openFile = new BinaryReader(File.Open(filename, FileMode.Open, FileAccess.Read));
             }
             catch (Exception)
             {
            return false;
             }

             try
             {
            if(openFile.ReadByte() != 58) /*read and test file magic number*/
            {
               return false;
            }
            /*loop and check if its a line /Rectangle or ellipse and put the values into
              data members.*/
            while (true)
            {
               tempByte = openFile.ReadByte();
               if(tempByte == (byte)DrawObjectType.Line)
               {
                  drawObject = new Line();
               }
               else if(tempByte == (byte)DrawObjectType.Rectangle)
               {
                  drawObject = new RectangleShape();
               }
               else if(tempByte == (byte)DrawObjectType.Ellipse)
               {
                  drawObject = new Ellipse();
               }

               drawObject.startPoint = new Point(openFile.ReadInt32(), openFile.ReadInt32());
               drawObject.endPoint = new Point(openFile.ReadInt32(), openFile.ReadInt32());
               drawObject.fillColour = Color.FromArgb(openFile.ReadInt32());
               drawObject.lineColour = Color.FromArgb(openFile.ReadInt32());
               drawObject.lineThickness = openFile.ReadInt32();
               drawObjectHistory.Add(drawObject);
            }
             }
             catch (EndOfStreamException)
             {
            status = true;
             }
             catch (Exception)
             {
            status = false;
             }
             finally
             {
            openFile.Close();
             }

             return status;
        }
示例#4
0
        private void panelMain_MouseDown(object sender, MouseEventArgs e)
        {
            toolStripStatusLabelCoordinates.Text = "X :" + e.X.ToString() + " Y:" + e.Y.ToString();
            this.starting = new Point(e.X, e.Y);
            this.tmpPoint = new Point(e.X, e.Y);
            this.mouseDown = true;

            if (radioButtonEllipse.Checked == true)
            {
                this.tmpLine = null;
                this.tmpEllipse = new Ellipse(this.starting.X, this.starting.Y, this.tmpPoint.X, this.tmpPoint.Y, Color.Transparent, this.dashPen);
                this.tmpRectangle = null;
            }
            else if (radioButtonLine.Checked == true)
            {
                this.tmpLine = new Line(this.starting, this.tmpPoint, this.dashPen);
                this.tmpEllipse = null;
                this.tmpRectangle = null;
            }
            else if (radioButtonRectangle.Checked == true)
            {
                this.tmpLine = null;
                this.tmpEllipse = null;
                this.tmpRectangle = new Rectangle(this.starting.X, this.starting.Y, this.tmpPoint.X, this.tmpPoint.Y, Color.Transparent, this.dashPen);
            }
        }
示例#5
0
文件: Form1.cs 项目: WilliamPring/SET
        /************************** Drawing Shape Related Events **************************/
        private void pnDrawScreen_MouseDown(object sender, MouseEventArgs e)
        {
            this.mouseDown = true;

            if (rbLine.Checked == true)
            {
                initialPoint = pnDrawScreen.PointToClient(Cursor.Position); //Get the starting point of the line
                endPoint = pnDrawScreen.PointToClient(Cursor.Position);
                newLineShape = new Line(initialPoint, endPoint);

                newLineShape.MyPen.Color = penType.Color;
                newLineShape.MyBrush.Color = brushColour.Color;
                newLineShape.MyPen.Width = penType.Width;
                newLineShape.MyPen.DashPattern = new float[] {5F, 5F, 5F, 5F};

                drawLineShape      = true; //Handle line
                drawRectangleShape = false;
                drawEllipseShape   = false;

                X = e.X;
                Y = e.Y;
                toolStripStatusLabel1.Text = "X: " + X.ToString() + " Y: " + Y.ToString();
            }
            else if(rbRectangle.Checked == true)
            {
                initialPoint = pnDrawScreen.PointToClient(Cursor.Position); //Get the starting point of the line
                endPoint = pnDrawScreen.PointToClient(Cursor.Position);
                newRectangleShape = new Rectangle(initialPoint, endPoint);

                newRectangleShape.MyPen.Color = penType.Color;
                newRectangleShape.MyBrush.Color = brushColour.Color;
                newRectangleShape.MyPen.Width = penType.Width;
                newRectangleShape.MyPen.DashPattern = new float[] {5F, 5F, 5F, 5F};

                drawRectangleShape = true; //Handle rectangle
                drawLineShape      = false;
                drawEllipseShape   = false;

                X = e.X;
                Y = e.Y;
                toolStripStatusLabel1.Text = "X: " + X.ToString() + " Y: " + Y.ToString();
            }
            else if(rbEllipse.Checked == true)
            {
                initialPoint = pnDrawScreen.PointToClient(Cursor.Position); //Get the starting point of the line
                endPoint = pnDrawScreen.PointToClient(Cursor.Position);
                newEllipseShape = new Ellipse(initialPoint, endPoint);

                newEllipseShape.MyPen.Color = penType.Color;
                newEllipseShape.MyBrush.Color = brushColour.Color;
                newEllipseShape.MyPen.Width = penType.Width;
                newEllipseShape.MyPen.DashPattern = new float[] { 5F, 5F, 5F, 5F };

                drawEllipseShape   = true; //Handle ellipse
                drawLineShape      = false;
                drawRectangleShape = false;

                X = e.X;
                Y = e.Y;
                toolStripStatusLabel1.Text = "X: " + X.ToString() + " Y: " + Y.ToString();
            }
        }