Пример #1
0
        // Return a copy of the graphic
        public override GraphicObject Copy(int _id)
        {
            // Create a new freehand line with the same attributes
            FreehandLine fhl = new FreehandLine(origColour, thickness, _id);

            // Add all the points to the new freehandline
            foreach (Point p in lines)
            {
                fhl.Update(p);
            }

            return(fhl);
        }
Пример #2
0
        // Load an existing file
        private void button13_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    // Open the text file using a stream reader
                    using (StreamReader sr = new StreamReader(ofd.FileName))
                    {
                        // Clear the old graphics
                        graphicObjectList.Clear();

                        string textLine;

                        while ((textLine = sr.ReadLine()) != null)
                        {
                            // Decode the object type
                            string type = textLine.TrimStart('{').Split(':')[1].Replace("\"", "").Split(',')[0];

                            // Determine type of object and then create the object and add it to the list of objects to be drawn
                            if (type.ToLower() == "line")
                            {
                                Line obj = new Line();
                                obj.Decode(textLine);

                                graphicObjectList.Add(obj);
                            }
                            else if (type.ToLower() == "freehandline")
                            {
                                FreehandLine obj = new FreehandLine();
                                obj.Decode(textLine);

                                graphicObjectList.Add(obj);
                            }
                            else if (type.ToLower() == "rectangle")
                            {
                                Rectangle obj = new Rectangle();
                                obj.Decode(textLine);

                                graphicObjectList.Add(obj);
                            }
                            else if (type.ToLower() == "square")
                            {
                                Square obj = new Square();
                                obj.Decode(textLine);

                                graphicObjectList.Add(obj);
                            }
                            else if (type.ToLower() == "ellipse")
                            {
                                Ellipse l = new Ellipse();
                                l.Decode(textLine);

                                graphicObjectList.Add(l);
                            }
                            else if (type.ToLower() == "circle")
                            {
                                Circle obj = new Circle();
                                obj.Decode(textLine);

                                graphicObjectList.Add(obj);
                            }
                            else if (type.ToLower() == "polygon")
                            {
                                Polygon obj = new Polygon();
                                obj.Decode(textLine);

                                graphicObjectList.Add(obj);
                            }
                        }
                    }

                    Redraw();
                }
                catch (Exception exc)
                {
                    MessageBox.Show("An error has occured./r/n" + exc.Message);
                }
            }
        }