public Shape(Shape shape) { this.Height = shape.Height; this.Width = shape.Width; this.Location = shape.Location; this.Rectangle = shape.rectangle; this.FillColor = shape.FillColor; this.LineColor = shape.LineColor; this.LineWidth = shape.LineWidth; this.TransformMatrix = shape.TransformMatrix; }
private RectangleShape CreateFrame(Shape shape) { RectangleF rect = shape.Rectangle; byte frameOffset = 5; float frameMargin = shape.LineWidth / 2 + frameOffset; rect.Inflate(frameMargin, frameMargin); RectangleShape frame = new RectangleShape(rect); frame.LineWidth = 2; frame.LineColor = Color.Black; frame.Transparency = 0; return frame; }
private void AddShape(Shape shape) { shapeNumber++; shape.ID = shapeNumber; IsChanged = true; Shapes.Add(shape); }
private void Form1_MouseDown(object sender, MouseEventArgs e) { pt1 = e.Location; Pen pen = new Pen(penColor, penWidth); shape = Shape.CreateShape(currentShape, pt1, pen); }
private void readShapesFileAsText(StreamReader reader) { // String rawText = reader.ReadToEnd(); //parse text while(reader.Peek()>0) { String line = reader.ReadLine(); string type =line.Split(new char[0])[0]; //Shape shape=null; //using the global shape obj he added switch (type) { case "Line": shape = new Line(); shape.readText(line); break; case "FreeLine": shape = new FreeLine(); shape.readText(line); break; case "Rect": shape = new Rect(); shape.readText(line); break; } shapeList.Add(shape); } }
private void readShapesFileAsBin(BinaryReader br) { while (br.PeekChar() > -1) { String line = br.ReadString(); string type = line.Split(new char[0])[0]; switch (type) { case "Line": shape = new Line(); shape.readText(line); break; case "FreeLine": shape = new FreeLine(); shape.readText(line); break; case "Rect": shape = new Rect(); shape.readText(line); break; } shapeList.Add(shape); } }
private void RemoveFromSelection(Shape shape) { dialogProcessor.Selection.Remove(shape); }
private void AddToSelection(Shape shape) { dialogProcessor.Selection.Add(shape); }
private void LoadShapeProperties(Shape shape) { SetXY(); tbWidth.Text = shape.Width.ToString(); tbHeight.Text = shape.Height.ToString(); btnLineColor.BackColor = shape.LineColor; btnFillColor.BackColor = shape.FillColor; numericLineWidth.Value = shape.LineWidth; transperancyTextBox.Text = shape.Transparency.ToString(); transperancyTrackBar.Value = shape.Transparency; }
private void EditShapeProperties(Shape shape) { if (shape != null) { EditShapePropertiesForm frmEditShapePropertiesForm = new EditShapePropertiesForm(shape); if (frmEditShapePropertiesForm.ShowDialog() == DialogResult.OK) { LoadShapeProperties(shape); } } }
private void ClickOnShape(Shape shape) { statusBar.Items[0].Text = "Last action: Click on shape"; if ((ModifierKeys & Keys.Control) == Keys.Control) { if (dialogProcessor.Selection.Contains(shape)) { RemoveFromSelection(shape); } else { AddToSelection(shape); } } else { dialogProcessor.Selection.Clear(); AddToSelection(shape); } dialogProcessor.IsDragging = true; }
private void openMenuItem_Click(object sender, EventArgs e) { //Open Menu & check condition if (dataModified) { // Offer to save drawing & display dialog DialogResult dialogResult = MessageBox.Show("Do you want to save changes?", "Form1", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); switch (dialogResult) { case DialogResult.Yes: writeFile(currentFile); break; case DialogResult.No: reset(); this.CreateGraphics().Clear(Form1.ActiveForm.BackColor); break; case DialogResult.Cancel: return; } } //open dialog String line = null; OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = "Text files(*.txt)|*.txt|Binary Files(*.bin)|*.bin|Serialized files(*.ser)|*.ser|XML files(*.xml)|*.xml|All files(*.*)|*.*"; dlg.InitialDirectory = Directory.GetCurrentDirectory(); if (dlg.ShowDialog() == DialogResult.Cancel) return; reset(); this.CreateGraphics().Clear(Form1.ActiveForm.BackColor); if (dlg.ShowDialog() == DialogResult.OK) { currentFile = dlg.FileName; //FileStream fs = new FileStream(currentFile, FileMode.Open); FileInfo fileInfo = new FileInfo(dlg.FileName); Graphics graphics = this.CreateGraphics(); // check for text files & selecting the shape if (fileInfo.Extension == ".txt") { FileStream fs = new FileStream(currentFile, FileMode.Open); StreamReader sr = new StreamReader(fs); while ((line = sr.ReadLine()) != null) { switch (line) { case "Line": currentShapeType = ShapeType.Line; break; case "Rect": currentShapeType = ShapeType.Rectangle; break; case "FreeLine": currentShapeType = ShapeType.FreeLine; break; case "Text": currentShapeType = ShapeType.Text; break; } shape = Shape.CreateShape(currentShapeType); shape.readText(sr); shape.Draw(graphics); shapeList.Add(shape); } sr.Close(); fs.Close(); } // Check for bin files & selecting encoding else if (fileInfo.Extension == ".bin") { FileStream fs = new FileStream(currentFile, FileMode.Open); BinaryReader br = new BinaryReader(fs); switch (br.ReadString()) { case "us-ascii": Shape.TextEncodingType = Encoding.ASCII; break; case "utf-8": Shape.TextEncodingType = Encoding.UTF8; break; case "u\0t\0f\0-\01\06\0": Shape.TextEncodingType = Encoding.Unicode; break; case "u\0\0\0t\0\0\0f\0\0\0-\0\0\03\0\0\02\0\0\0": Shape.TextEncodingType = Encoding.UTF32; break; case "\0u\0n\0i\0c\0o\0d\0e\0F\0F\0F\0E": Shape.TextEncodingType = Encoding.BigEndianUnicode; break; case "utf-7": Shape.TextEncodingType = Encoding.UTF7; break; } br = new BinaryReader(fs, Shape.TextEncodingType); int length = (int)br.BaseStream.Length; MessageBox.Show(length.ToString()); while (br.PeekChar() != -1) { // Selecting shape for bin file & recreating the figures switch (br.ReadString()) { case "Line": currentShapeType = ShapeType.Line; shape = Shape.CreateShape(currentShapeType); shape.readBinary(br); shape.Draw(graphics); shapeList.Add(shape); break; case "Rect": currentShapeType = ShapeType.Rectangle; shape = Shape.CreateShape(currentShapeType); shape.readBinary(br); shape.Draw(graphics); shapeList.Add(shape); break; case "FreeLine": currentShapeType = ShapeType.FreeLine; shape = Shape.CreateShape(currentShapeType); shape.readBinary(br); shape.Draw(graphics); shapeList.Add(shape); break; case "Text": currentShapeType = ShapeType.Text; shape = Shape.CreateShape(currentShapeType); shape.readBinary(br); shape.Draw(graphics); shapeList.Add(shape); break; } } fs.Close(); } else if (fileInfo.Extension == ".ser") { FileStream fs = new FileStream(currentFile, FileMode.Open); BinaryFormatter bf = new BinaryFormatter(); shapeList = (List<Shape>)bf.Deserialize(fs); foreach (Shape shape in shapeList) shape.Draw(graphics); fs.Close(); }//end ser else if (fileInfo.Extension == ".xml") { XDocument document = XDocument.Load(currentFile); XElement root = document.Root; foreach (XElement xe in root.Elements()) { switch (xe.Name.ToString()) { case "Line": currentShapeType = ShapeType.Line; break; case "Rect": currentShapeType = ShapeType.Rectangle; break; case "FreeLine": currentShapeType = ShapeType.FreeLine; break; case "Text": currentShapeType = ShapeType.Text; break; } shape = Shape.CreateShape(currentShapeType); foreach (XElement xee in xe.Elements()) { shape.readXmlElement(xee); } shape.Draw(graphics); shapeList.Add(shape); //fs1.Close(); }// End xml } } }
private void Form1_MouseDown(object sender, MouseEventArgs e) { if (currentShapeType == ShapeType.None) { MessageBox.Show("Must select shape type"); return; } pt1 = e.Location; Console.WriteLine("currentShapeType = {0}", currentShapeType); shape = Shape.CreateShape(currentShapeType); shape.Pt1 = pt1; shape.PenColor = Color.Black; //shape.Pen = penTemp; Shape.MouseIsDown = true; Shape.CurrentShape = shape; }
public virtual void DrawShape(Graphics grfx, Shape item) { item.DrawSelf(grfx); }
public EditShapePropertiesForm(Shape originalShape) { InitializeComponent(); shape = originalShape; EnagleOrDisableCoordinates(); }