private void cizimAlani_MouseMove(object sender, MouseEventArgs e) { Graphics g = cizimAlani.CreateGraphics(); SolidBrush f = new SolidBrush(defColor); if (draw && e.X <= 820 && e.Y <= 797 && e.X >= 0 && e.Y >= 0) { if (shapeName == "rectangle") { shape = new Rectangle(); g.Clear(Color.White); drawAgain(); shape.shapeName = shapeName; shape.startX = tempX; shape.startY = tempY; shape.Color = defColor; shape.draw(g, f, e.X, e.Y); } else if (shapeName == "daire") { shape = new Daire(); g.Clear(Color.White); drawAgain(); shape.shapeName = shapeName; shape.startX = tempX; shape.startY = tempY; shape.Color = defColor; shape.draw(g, f, e.X, e.Y); } else if (shapeName == "triangle") { shape = new Triangle(); g.Clear(Color.White); drawAgain(); shape.shapeName = shapeName; shape.startX = tempX; shape.startY = tempY; shape.Color = defColor; shape.draw(g, f, e.X, e.Y); } else if (shapeName == "hexagon") { shape = new Hexagon(); g.Clear(Color.White); drawAgain(); shape.shapeName = shapeName; shape.startX = tempX; shape.startY = tempY; shape.Color = defColor; shape.draw(g, f, e.X, e.Y); } } }
private void btnOpenFromFile_Click(object sender, EventArgs e) { OpenFileDialog file = new OpenFileDialog(); file.Filter = "Metin Belgesi |*.txt"; file.Multiselect = false; try { if (file.ShowDialog() == DialogResult.OK) { string filePath = @file.FileName; FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read); StreamReader sw = new StreamReader(fs); string line, _shape, clr; string[] values; int bX, bY, sX, sY; Graphics g = cizimAlani.CreateGraphics(); g.Clear(Color.White); shapes.Clear(); SolidBrush brush = new SolidBrush(Color.White); while (!sw.EndOfStream) { line = sw.ReadLine(); values = line.Split(' '); _shape = values[0]; bX = int.Parse(values[1]); bY = int.Parse(values[2]); sX = int.Parse(values[3]); sY = int.Parse(values[4]); clr = values[5]; if (clr == "Red") { brush.Color = Color.Red; } else if (clr == "Blue") { brush.Color = Color.Blue; } else if (clr == "Green") { brush.Color = Color.Green; } else if (clr == "Orange") { brush.Color = Color.Orange; } else if (clr == "Black") { brush.Color = Color.Black; } else if (clr == "Yellow") { brush.Color = Color.Yellow; } else if (clr == "Purple") { brush.Color = Color.Purple; } else if (clr == "Brown") { brush.Color = Color.Brown; } else if (clr == "Gray") { brush.Color = Color.Gray; } if (_shape == "rectangle") { shape = new Rectangle(); shape.shapeName = _shape; shape.startX = bX; shape.startY = bY; shape.Color = brush.Color; shape.draw(g, brush, sX, sY); } else if (_shape == "daire") { shape = new Daire(); shape.shapeName = _shape; shape.startX = bX; shape.startY = bY; shape.Color = brush.Color; shape.draw(g, brush, sX, sY); } else if (_shape == "triangle") { shape = new Triangle(); shape.shapeName = _shape; shape.startX = bX; shape.startY = bY; shape.Color = brush.Color; shape.draw(g, brush, sX, sY); } else if (_shape == "hexagon") { shape = new Hexagon(); shape.shapeName = _shape; shape.startX = bX; shape.startY = bY; shape.Color = brush.Color; shape.draw(g, brush, sX, sY); } shapes.Add(shape); } sw.Close(); fs.Close(); } } catch { MessageBox.Show("Dosya Okunurken Bir Sorun Oluştu!"); } }