private void ShowObject(GraphicalObject data, int x, int y) { using (Graphics g = pictureBox1.CreateGraphics()) { drawObject(g, data, x, y); } }
private void loadData(string fileName) { ClearData(); using (StreamReader reader = new StreamReader(fileName)) { string line; while ((line = reader.ReadLine()) != null) { GraphicalObject obj = LineToGraphicalObject(line); AddData(obj); } } }
private void okButton_Click(object sender, EventArgs e) { if (comboBox1.SelectedIndex < 0) { comboBox1.Focus(); DialogResult = DialogResult.None; return; } Value = new GraphicalObject(); Value.type = (ObjectType)comboBox1.SelectedItem; Value.dx = (int)dxUpDown.Value; Value.dy = (int)dyUpDown.Value; }
private GraphicalObject LineToGraphicalObject(string line) { string[] parts = line.Split(','); if (parts.Length != 3) { throw new InvalidDataException("Line format incorrect."); } GraphicalObject obj = new GraphicalObject(); obj.type = (ObjectType)Int16.Parse(parts[0]); obj.dx = Int32.Parse(parts[1]); obj.dy = Int32.Parse(parts[2]); return(obj); }
private void drawObject(Graphics g, GraphicalObject data, int x, int y) { switch (data.type) { case ObjectType.LINE: g.DrawLine(Pens.Black, x, y, x + data.dx, y + data.dy); break; case ObjectType.RECTANGLE: g.DrawRectangle(Pens.Black, x, y, data.dx, data.dy); break; case ObjectType.CIRCLE: g.DrawEllipse(Pens.Black, x, y, data.dx, data.dy); break; default: break; } // Refresh(); }
private void AddData(GraphicalObject obj) { objects.Add(obj); listBox1.Items.Add(obj); objectCountLabel.Text = objects.Capacity.ToString(); }